IBAction button change color?
I 开发者_高级运维have created a button in interface builder and set its type as custom. I want to change the background color of the button based on the button's tag when the view loads. How can i do this?
Button added to Xib, tag set to 1.
View header:
@property (nonatomic, retain) IBOutlet UIButton *myButton;
In interface builder, bound myButton to button.
Then programmatically in viewDidLoad, conditionally set based on tag value:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([myButton tag] == 1)
{
[myButton setBackgroundColor:[UIColor blueColor]];
}
else
{
[myButton setBackgroundColor:[UIColor greenColor]];
}
}
精彩评论