iphone 改变按钮的背景颜色

1:原文摘自:http://www.cnblogs.com/APTX4869/archive/2011/03/10.html

http://www.cocoachina.com/bbs/read.php?tid-48666-keyword-UIButton.html

初始设置:
UIImage *bgImg1 = [UIImage imageNamed:@"Selected.png"];
UIImage *bgImg2 = [UIImage imageNamed:@"Unselected.png"];
[btn setImage:bgImg2 forState:UIControlStateNormal];
[btn setImage:bgImg1 forState:UIControlStateSelected];

然后在button的Action方法改变button状态:
- (IBAction) buttonTouch:(id)sender
{
    UIButton *button = (UIButton *)sender;
    button.selected = !button.selected;
}

 

 

posted on 2011-12-06 09:47  wtq  阅读(1033)  评论(0编辑  收藏  举报