您的位置:首页 > 产品设计 > UI/UE

button点击切换背景图片的问题

2014-12-11 15:50 411 查看
我做了个UIButton的扩展,代码如下:

#import <UIKit/UIKit.h>

@interface CheckBoxButton : UIButton
@property (nonatomic,assign) BOOL isChecked;
@end

我通过下面代码来实现点击后切换图片,但是并不能达到效果
if (button.isChecked) {
self.collectionButton.imageView.image = [UIImage imageNamed:@"shouchang_do"];

}else
{
self.collectionButton.imageView.image = [UIImage imageNamed:@"shouchang_undo"];

}


这样设置后,点击按钮,图片并没有变换,解决办法:
if (button.isChecked) {
//self.collectionButton.imageView.image = [UIImage imageNamed:@"shouchang_do"];
[self.collectionButton setImage:[UIImage imageNamed:@"shouchang_do"] forState:UIControlStateNormal];
}else
{
//self.collectionButton.imageView.image = [UIImage imageNamed:@"shouchang_undo"];
[self.collectionButton setImage:[UIImage imageNamed:@"shouchang_undo"] forState:UIControlStateNormal];

}
这样就可以了,具体还没知道原因!!,有知道的请多多指点哈
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios开发 uibutton 图片