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()
}
Swift3 倒计时按钮扩展的更多相关文章
- iOS 短信验证码倒计时按钮的实现
验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...
- angularjs使用directive实现倒计时按钮
前不久在做一个彩票的项目时,有一个手动开奖的需求.所以有了这个倒计时按钮.下面分享下具体的代码: 效果: 代码: App.directive('timerBtn', function() { // 倒 ...
- delphi倒计时按钮写法
procedure TForm1.FormActivate(Sender: TObject); var i: Integer; begin btn8.Enabled:=False; do begin ...
- jquery倒计时按钮常用于验证码倒计时
<!doctype html><html><head> <meta charset="utf-8"> <title>jq ...
- React实战之60s倒计时按钮(发送短信验证按钮)
React实战之60s倒计时按钮——短信验证按钮 导入:(antd组件——Form表单) import { Button, Form, Input } from 'antd'; const FormI ...
- 前端学习——ionic/AngularJs——获取验证码倒计时按钮
按钮功能为:点击"获取验证码"--按钮不可用-设置倒计时-60秒后重新获取. 代码借鉴于:http://plnkr.co/edit/Swj82MpJSix3a47jZRHP?p= ...
- Android 倒计时按钮,倒计时发送短信验证码…
Android基础之——CountDownTimer类,轻松实现倒计时功能https://www.cnblogs.com/yfceshi/p/6853746.html android中获取验证码后出现 ...
- Android中注册获取验证码倒计时按钮
public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param t ...
- UWP 发送短信公用倒计时按钮
1.要求: 发送验证码按钮,点击后,会倒计时60s,之后才能再次点击.不同界面的多个验证码按钮共享这个倒计时时间. 2.操作步骤 1) 从登录界面-->忘记密码输入手机号- ...
随机推荐
- Shell脚本中$0、$?、$!等的意义
变量说明$$ Shell本身的PID(ProcessID)$! Shell最后运行的后台Process的PID$? 最后运行的命令的结束代码(返回值)$- 使用Set命令设定的Flag一览$* 所有参 ...
- 解决Address is in use:Windows和Linux通过杀死进程
在开发无卡支付系统的过程中,因为用了端口来监听服务,在调试程序的时候,忘了关,再次运行的时候会出现Address is in use的问题,即端口已经被绑定,无法再次使用,最直观的方法就是杀死之前的进 ...
- 简单的node 服务端 响应get,返回json数据;
原文:http://blog.csdn.net/xn_28/article/details/50837019 const http = require('http'); const hostname ...
- Python3字符编码
编码 字符串是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节 ...
- wait()和sleep()的区别
wait()是Object类的方法,当一个线程执行到wait()方法时,该线程就进入到一个和该线程相关的等待池中,同时释放了对象锁(暂时失去对象锁,wait(long timeout)超时时间到后还需 ...
- [linux]Linux如何查看文件中的中间部分内容
最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /etc/passwd 2. 如果你想查看文件的后10行,可以使用tail命令,如: ...
- 条件随机场_CRF
无向图 举例:“Bob drank coffee at Starbucks” 标记方式1:(名词,动词,名词,介词,名词) 称为l 标记方式2:(名词,动词,动词,介词,名词) 挑选出一个最靠谱的: ...
- jquery plugin 之 form表单验证插件
基于h5表单验证系统.扩展了对easyui组件的支持 先上图: 提示样式用到了伪对象的 {content: attr(xxx)}函数方法,实现提示信息能动态切换. 1.关键属性说明: type: 表单 ...
- python之web开发“三剑客”
# django import django # flask import flask # tornado import tornado
- ajax在jQuery中的应用 (1)加载异步数据