2011-08-05 88 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]