问题描述
我正在使用 UIButton ,而xib backgroundImage为 check_box_off.png ,同时单击atmbtn backgroundImage更改为 check_box_on.png ,同时 NSLog 打印 yesString ,然后再次单击atmbtn,backgroundImage不变. check_box_on.png ,同时NSLog仅打印相同的 yesString ..一次又一次地叮当响atmbutton相同..
I am using UIButton with xib backgroundImage is check_box_off.png, while clicking the atmbtn backgroundImage change to check_box_on.png meanwhile NSLog printing yesString and again clicking atmbtn there is no change in backgroundImage same check_box_on.png meanwhile NSLog Printing same yesString only.. again and again clinking the atmbutton same only happening..
- (IBAction)atmAction:(id)sender{
if( [atmbtn backgroundImageForState:UIControlStateNormal] ==
[UIImage imageNamed:@"check_box_on.png"] ) {
[atmbtn setImage:[UIImage imageNamed:@"check_box_off.png"]
forState:UIControlStateNormal];
noString = @"No";
NSLog(@"atm=%@",noString);
} else if( [atmbtn backgroundImageForState:UIControlStateNormal] ==
[UIImage imageNamed:@"check_box_off.png"]) {
[atmbtn setImage:[UIImage imageNamed:@"check_box_on.png"]
forState:UIControlStateNormal];
yesString = @"Yes";
NSLog(@"atm = %@",yesString);
}
}
NSLog打印:
atm =是
atm =是
atm =是
我该如何解决?请分享您的想法.
how Could I resolve this? Please Share your Ideas.
推荐答案
使用此:
[atmbtn setBackgroundImage:[UIImage imageNamed:@"check_box_on.png"] forState:UIControlStateNormal];
这篇关于如何在单击同一UIbutton的同时更改UIButton backgroundimage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!