美文网首页
多个UIButton交替点击实现

多个UIButton交替点击实现

作者: Demoer | 来源:发表于2016-09-21 11:45 被阅读90次
//
//  ViewController.h
//  UIButtonApply
//
//  Created by zhyunfe on 16/9/21.
//  Copyright © 2016年 zhyunfe. All rights reserved.
//

#import <UIKit/UIKit.h>

/*
 //MARK: -Navigation
 //在UI中展示两个Button,btn1和btn2,
 //当点击一个btn1的时候,btn1.enable = false,btn2.enable = true
 //当点击btn2的时候,btn2.enable = false,btn1.enable = true
 */

@interface ViewController : UIViewController
{
    //创建一个全局的button来存放不可用btn
    UIButton *_button;
}
- (IBAction)btn1Click:(UIButton *)sender;
- (IBAction)btn2Click:(UIButton *)sender;

@end
- (IBAction)btn1Click:(UIButton *)sender {
    //将被点击的按钮状态设置为false,让全局中存储的之前的btn的状态设置为true,然后将本次点击的btn存储到全局的button中,这样就保证了全局的button存放的一直是不可用的btn,当点击另外一个按钮的时候,释放不可用的btn
    _button.enabled = true;
    sender.enabled = false;
    _button = sender;

}

- (IBAction)btn2Click:(UIButton *)sender {
    _button.enabled = true;
    sender.enabled = false;
    _button = sender;
}
@end

GitHub源码

相关文章

网友评论

      本文标题:多个UIButton交替点击实现

      本文链接:https://www.haomeiwen.com/subject/ztlaettx.html