iOS实现按钮点击选中与被选中切换功能
时间:2021-03-21 10:28:45|栏目:iOS代码|点击: 次
其实这个没什么记的,初始化按钮给按钮分别设置选中时对图片和被选中时的图片,给按钮添加方法,在方法中实现三句话就OK了,下面直接看代码:
首先在.m中声明一个按钮
@property (nonatomic, strong) UIButton *selecBtn;
//初始化按钮
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
//给按钮设置图片
[button setBackgroundImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:SeleimageArray[i]] forState:UIControlStateDisabled];
//添加方法
[button addTarget:self action:@selector(changeDataButton:) forControlEvents:UIControlEventTouchDown];
然后在方法中如下:
- (IBAction)btnClick:(UIButton *)btn {
self.selecBtn.enabled = YES;
btn.enabled = NO;
self.selecBtn = btn;
}
上一篇:完整的iOS新浪微博分享功能开发
栏 目:iOS代码
本文标题:iOS实现按钮点击选中与被选中切换功能
本文地址:http://www.codeinn.net/misctech/84897.html






