Abhishek
Abhishek

Reputation: 303

Change UILabel background color

my code is

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

pTeamAlreadybl.text=@" 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];

How can I change label's background color?

Upvotes: 2

Views: 3708

Answers (4)

Sandeep Khade
Sandeep Khade

Reputation: 2832

[pTeamAlreadybl setBackgroundColor:[UIColor YourColor]];

YourColor as mentioned below

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

you can use customized color as well like this

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

Upvotes: 0

Plague
Plague

Reputation: 466

To change the background color of a UILabel, you need to set the backgroundColor property of the UILabel object. You can do so by using the following line of code:

[pTeamAlreadybl setBackgroundColor:[UIColor colorOfYourChoice]];

OR

pTeamAlreadybl.backgroundColor = [UIColor colorOfYourChoice];

Upvotes: 5

Ruchir
Ruchir

Reputation: 151

You miss

pTeamAlreadybl.backgroundColor=[UIColor anycolor];

write this code

Upvotes: 6

Vladimir
Vladimir

Reputation: 170839

pTeamAlreadybl.backgroundColor = [UIColor ...];

Doesn't the above code work?

Upvotes: 1

Related Questions