如何在单击同一UIbutton的同时更改UIButton backgroundimage? [英] How to change UIButton backgroundimage while clicking same UIbutton?

查看:55
本文介绍了如何在单击同一UIbutton的同时更改UIButton backgroundimage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆