__block int time = ;
__block UIButton *verifybutton = _GetverificationBtn;
verifybutton.enabled = NO;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, );
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, , ,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, ),1.0*NSEC_PER_SEC, ); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(time<=){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
verifybutton.backgroundColor = [UIColor colorWithHexString:@"FC740A"];
[verifybutton setTitle:@"获取验证码" forState:UIControlStateNormal];
verifybutton.enabled = YES;
});
}else{
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
verifybutton.backgroundColor = [UIColor grayColor];
NSString *strTime = [NSString stringWithFormat:@"获取验证码(%d)",time];
[verifybutton setTitle:strTime forState:UIControlStateNormal];
verifybutton.titleLabel.textColor = [UIColor whiteColor];
});
time--;
}
});
dispatch_resume(_timer);

button获取验证码60秒倒计时 直接用的更多相关文章

  1. iOS-登录发送验证码时60秒倒计时,直接用

    __block NSInteger timeout= ; //倒计时时间 KWeakSelf dispatch_queue_t queue = dispatch_get_global_queue(DI ...

  2. uni验证码60秒倒计时

    其实要实现这个功能原理非常简单,就是setInterval+setTimeout+clearInterval结合使用,首先在data里定义一个变量second,初始值为60,然后在setInterva ...

  3. js实现60秒倒计时效果(使用了jQuery)

    今天碰到要实现一个类似那种短信验证码60秒倒计时的需求,好久不写js,有点手生.把代码记录下,方便后续查阅. 这里我用了jQuey,毕竟写起来简洁点.下面直接看效果和代码. 一.效果          ...

  4. 微信小程序60秒倒计时

    微信小程序发送短信验证码后60秒倒计时功能,效果图: 完整代码 index.wxml <!--index.wxml--> <view class="container&qu ...

  5. 获取验证码,60秒倒计时js

    <input type="button" id="btn" value="免费获取验证码" /><script type= ...

  6. jQuery实现发送短信验证码后60秒倒计时

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  7. iOS “获取验证码”按钮的倒计时功能

    iOS 的倒计时有多种实现细节,Cocoa Touch 为我们提供了 NSTimer 类和 GCD 的dispatch_source_set_timer方法去更加方便的使用计时器.我们也可以很容易的的 ...

  8. Angular.js 使用获取验证码按钮实现-倒计时

    获取验证码界面效果如图: 需要实现以下逻辑 按钮不可选 --输入电话号码,按钮可选 --点击获取,进入倒计时,按钮不可选 --倒计时结束,回到初识状态 核心代码: var cd = 60; var t ...

  9. 点击按钮出现60秒倒计时js代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. js高级-递归调用

    函数调用自身 求1-100的和 var sum = 0; for(var i = 1; i<=100; i++){ sum += i } console.log(sum) //自己写的递归 va ...

  2. 移动端web页面滚动不流畅,卡顿闪烁解决方案

    移动端web页面滚动不流畅,卡顿闪烁解决方案   1.ios端的-webkit-overflow-scrolling属性可控制页面滚动效果,设置如下实现惯性滚动和弹性效果: -webkit-overf ...

  3. centos7 增加虚拟网卡

    确认内核是否有tun模块 # modinfo tun yum install tunctl -y 如果找不到 vim /etc/yum.repos.d/nux-misc.repo [nux-misc] ...

  4. OpenCV SVM

    #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <ope ...

  5. hive 踩坑

    1. create tabl metastore.MetaStoreDirectSql: Self-test query [select "DB_ID" from "DB ...

  6. MySql数据库常用语句汇总

    第一天1.登陆数据库 mysql -uroot -proot; //-u用户名 -p密码2.启动数据库 net start mysql;3.创建表空间(数据库)create database qy97 ...

  7. new.target

    [new.target] The new.target property lets you detect whether a function or constructor was called us ...

  8. SpringBoot点滴(1)

    spring boot 注意事项 1.项目启动的主类,放置位置在所有类的外层与controller,dao,service,util,entity同层,SpringBoot会自动扫描@SpringBo ...

  9. Dubbo启动过程(Spring方式)详解

    一.使用Spring xml配置方式的启动过程 1. 解析XML,注册Bean 2. 监听Spring事件 3. 启动或关闭dubbo 二.详细过程 1. 解析XML,注册Bean 利用Spring提 ...

  10. 关于U3D图片的压缩格式

    http://blog.sina.com.cn/s/blog_930ffa0b0102vass.html