我做了个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]; }这样就可以了,具体还没知道原因!!,有知道的请多多指点哈
原文地址:http://blog.csdn.net/feixiang_song/article/details/41867809