zoukankan      html  css  js  c++  java
  • Swift3 倒计时按钮扩展

    extension UIButton{
        func overrideSelf(){
            self.setTitle("验证码", for: .normal)
            self.titleLabel?.font = UIFont.systemFont(ofSize: 13)
            self.addTarget(self, action: #selector(tf), for: .touchUpInside)
            self.setTitleColor(UIColor.orange, for: .normal)
            self.layer.cornerRadius = 15
            self.layer.borderWidth = 1
            self.layer.borderColor = color_navView.cgColor
            self.layer.masksToBounds = true
        }
        
        func tf(){
            Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(timerAction(timer:)), userInfo: nil, repeats: true).fire()
        }
        
        func timerAction(timer:Timer){
            tag -= 1
            if tag < 0 {
                self.isUserInteractionEnabled  = true
                self.layer.borderColor = color_navView.cgColor
                self.setTitle("重新获取", for: .normal)
                self.setTitleColor(UIColor.orange, for: .normal)
                timer.invalidate()
                tag = 30
            }else{
                self.isUserInteractionEnabled = false
                self.layer.borderColor = UIColor.gray.cgColor
                self.setTitle("剩余(tag)s", for: .normal)
                self.setTitleColor(UIColor.gray, for: .normal)
            }
        }
        
        func getVerificationCode(){
           //let st = STools()
           // st.getVercodeAction(cityCode: appDelegate.cityCode, mobile: appDelegate.vphone, verificationCodeType: appDelegate.verificationStr)
           // st.verificationInfo { (info:String) in
           //    if info != "验证码已发送"{//失败了
           //       self.tag = 0
           //   }
           //     appDelegate.window.rootViewController?.showHint(info)
           // }
      }
    }
    
    //MARK:调用
            codeBtn.overrideSelf()
            codeBtn.tag = 30
            codeBtn.addTarget(self, action: #selector(getVercodeAction(_:)), for: .touchUpInside)
    
        func getVercodeAction(_ sender: Any) {
            codeBtn.getVerificationCode()
        }
    

      

  • 相关阅读:
    弄清变量名字空间
    Perl中文编码的处理
    了解魔符的含义
    Log::Minimal 小型可定制的log模块
    Perl – 文件测试操作符
    在源代码中使用Unicode字符
    editplus乱码charset的奇怪问题
    ASP.NET程序中常用代码汇总(一)
    ASP.NET程序中常用代码汇总(三)
    ASP.NET程序中常用代码汇总(二)
  • 原文地址:https://www.cnblogs.com/mapanguan/p/6386720.html
Copyright © 2011-2022 走看看