开发者

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]];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜