zoukankan      html  css  js  c++  java
  • iOS 学习笔记-关于Button

     

         在工作中遇到的需求是 一个按钮要有两种状态,按住要发布语音,同时文字也要改变,经过尝试才知道一个Button 可以添加两种事件,小伙伴们遇到过吗?

      //获取发布语音button
        self.pulishBtn = [pulishVocieView viewWithTag:103];
        [self.pulishBtn addTarget:self action:@selector(pulishBtnTouchDown:) forControlEvents: UIControlEventTouchDown];
        [self.pulishBtn addTarget:self action:@selector(pulishBtnTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
        //获取提示label
        self.label = (UILabel *)[pulishVocieView viewWithTag:104];
    

        还有一个需求是说 一个按钮要点击后,要由关注变成加关注,笔者的想法是利用两种状态,一个是默认,一个是被选中状态,结果去试了后,无论怎么点击,只有最后一个Cell的Button改变了,这下笔者可是蒙了,最后的解决的办法如下

     UIButton *ActtonBtn = (UIButton *)[cell.contentView viewWithTag:104];
        [ActtonBtn addTarget:self action:@selector(ActtionClick:) forControlEvents:UIControlEventTouchUpInside];
        ActtonBtn.cornerRadius = 3;
    //    self.auttenBtn = ActtonBtn;
        ActtonBtn.tag = self.count;
        self.count++;
    

     在最上面有个属性,重改tag值就搞定了这个逻辑

    @property (nonatomic, assign) int count;
    
  • 相关阅读:
    Sublime Text 3 格式化HTML CSS JS 代码
    CSS 温故而知新
    JQuery Mobile 学习笔记
    Eclipse ADT 代码注释模版
    Eclipse ADT 与VS 常用的快捷键 对比学习
    元组、文件、以及其他
    类型与运算
    python
    python 内置函数 lamda表达式。 open 文件方法
    python 基础 基本数据类型
  • 原文地址:https://www.cnblogs.com/nqs674/p/5285017.html
Copyright © 2011-2022 走看看