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()
}

  

Swift3 倒计时按钮扩展的更多相关文章

  1. iOS 短信验证码倒计时按钮的实现

    验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...

  2. angularjs使用directive实现倒计时按钮

    前不久在做一个彩票的项目时,有一个手动开奖的需求.所以有了这个倒计时按钮.下面分享下具体的代码: 效果: 代码: App.directive('timerBtn', function() { // 倒 ...

  3. delphi倒计时按钮写法

    procedure TForm1.FormActivate(Sender: TObject); var i: Integer; begin btn8.Enabled:=False; do begin ...

  4. jquery倒计时按钮常用于验证码倒计时

    <!doctype html><html><head> <meta charset="utf-8"> <title>jq ...

  5. React实战之60s倒计时按钮(发送短信验证按钮)

    React实战之60s倒计时按钮——短信验证按钮 导入:(antd组件——Form表单) import { Button, Form, Input } from 'antd'; const FormI ...

  6. 前端学习——ionic/AngularJs——获取验证码倒计时按钮

     按钮功能为:点击"获取验证码"--按钮不可用-设置倒计时-60秒后重新获取. 代码借鉴于:http://plnkr.co/edit/Swj82MpJSix3a47jZRHP?p= ...

  7. Android 倒计时按钮,倒计时发送短信验证码…

    Android基础之——CountDownTimer类,轻松实现倒计时功能https://www.cnblogs.com/yfceshi/p/6853746.html android中获取验证码后出现 ...

  8. Android中注册获取验证码倒计时按钮

    public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param t ...

  9. UWP 发送短信公用倒计时按钮

    1.要求:      发送验证码按钮,点击后,会倒计时60s,之后才能再次点击.不同界面的多个验证码按钮共享这个倒计时时间. 2.操作步骤       1) 从登录界面-->忘记密码输入手机号- ...

随机推荐

  1. MySQL Workbench常用快捷键

    执行当前SQL语句(即鼠标所在的SQL语句,以 ; 结尾) Ctrl + Enter 执行选中的SQL语句(或执行所有SQL语句) Ctrl + Shift + Enter

  2. SSH无法连上CentOS7的问题

    今天安装完带GNOME的CentOS后发现XShell无法连接上Linux. 原因是sshd服务没有开启.下面是解决办法: 1 ip addr 发现网卡名称为ens33 2 在/etc/sysconf ...

  3. maven web+spring mvc项目没有出现src/main/java路径

    直接在main 文件夹下创建java可以解决 https://www.cnblogs.com/zhujiabin/p/6343462.html

  4. JavaScript调用wcf服务,并且处理返回的字典集合

    1.第一步创建wcf服务的方法 using System;using System.Collections.Generic;using System.Linq;using System.Runtime ...

  5. maven mirror , profile , snapshot 和release

    1. settings.xml 配置的mirror <mirrors> <mirror> <id>Nexus</id> <name>nexu ...

  6. JS在页面根据数量改变总价及按钮进行格式验证

    分两部分,第一部分是在页面上,根据数量的input标签内容,动态更新总价标签的内容,代码如下: <script type="text/javascript"> $(do ...

  7. centOS 6.5下升级mysql,从5.1升级到5.6

    转载:https://www.cnblogs.com/vickygu2007/p/5066409.html #mysqldump -uroot -p --all-databases > data ...

  8. 【51NOD】1006 最长公共子序列Lcs(动态规划)

    给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为:   abcicba abdkscab   ab是两个串的子序列,abc也是,abca也是,其中abca是这两个 ...

  9. 网络编程之IO模型

    IO模型的分类 blocking IO:阻塞IO nonblocking IO:非阻塞IO IO multiplexing:IO多路复用 signal driven IO:异步IO 通常情况下IO默认 ...

  10. css扩大超链接的点击范围

    给a标签设置display:block后,它会根据盒模型计算a标签的实际大小.这时候,你可以使用hover伪类使a的整个盒模型生效..link a{display:block;padding:2px ...