源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

iOS实现按钮点击选中与被选中切换功能

  • 时间:2020-02-15 11:06 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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实现按钮点击选中与被选中切换功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部