2011-08-05 91 views
2

我的代碼是更改的UILabel的背景顏色

UILabel *pTeamAlreadybl=[[UILabel alloc]initWithFrame:CGRectMake(110, 275,180,30)]; 

[email protected]" Team already?"; 
pTeamAlreadybl.font=[UIFont boldSystemFontOfSize:16]; 
pTeamAlreadybl.textAlignment=UITextAlignmentLeft; 
pTeamAlreadybl.textColor=[UIColor colorWithRed:61.0/255.0 green:61.0/255.0 blue:61.0/255.0 alpha:0.6]; 
pTeamAlreadybl.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.7]; 

如何更改標籤的背景顏色?

回答

6

你錯過

pTeamAlreadybl.backgroundColor=[UIColor anycolor]; 

寫這段代碼

1
pTeamAlreadybl.backgroundColor = [UIColor ...]; 

沒有上面的代碼工作?

5

要更改UILabel的背景顏色,您需要設置UILabel對象的backgroundColor屬性。您可以使用下面的代碼行這樣做:

[pTeamAlreadybl setBackgroundColor:[UIColor colorOfYourChoice]]; 

OR

pTeamAlreadybl.backgroundColor = [UIColor colorOfYourChoice]; 
0
[pTeamAlreadybl setBackgroundColor:[UIColor YourColor]]; 

YourColor下面

blackColor提到;
darkGrayColor; lightGrayColor whiteColor;
grayColor;
redColor;
greenColor;
blueColor;
cyanColor;
yellowColor;
magentaColor; orangeColor;
purpleColor;
brownColor;
clearColor;

您可以使用自定義的顏色,以及這樣

[UIColor colorWithRed:61.0/255.0 green:61.0/255.0 blue:61.0/255.0 alpha:0.6]