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];
}
这样就可以了,具体还没知道原因!!,有知道的请多多指点哈
#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中点击button切换背景图片与点击切换背景颜色问题的解释
- 点击Button选择切换背景图片设置
- ios:点击一个button不断切换背景图片
- WPF之路二: button添加背景图片点击后图片闪烁问题
- 点击button,button背景图片变化
- IE6下通过a标签点击切换图片的问题
- ImageButton图片背景的切换
- Button 点击切换背景
- 无js实现点击图片切换背景css3
- 关于在IE-8下 button的背景图片不能正确显示的问题
- AndEngine Button(2)——点击切换显示图片Button
- android:drawableLeft的Button不能切换图片问题之解决办法
- 给Button按钮设置背景图片在IE下不能正确显示的问题
- 淡入淡出(折叠效果)and点击切换背景图片
- Android中点击button,实现ImageView中图片的循环切换
- 【经验小谈】设置按钮点击背景 button设置点击背景 控件设置切换背景 找不到@color 没有@color属性 没有color属性
- 在java代码中设置控件的margin 属性 及 button点击切换背景
- Button的背景使用selector图片无法显示的问题
- iOS之点击按钮切换背景图片
- andoid点击按钮(ImageButton)时改变按钮的背景图片 SelectorDemo