在app 注册或者登录 需要验证码的地方、为了避免短时间内刷验证码、往往会加上一层验证。

倒计时结束后、可以重新获取!

代码实现如下:

// _CountdownTime 倒计时总时间;
//_timer 定时器
- (void)startTime:(UIButton *)VerificationCodeButton
{
__block NSInteger timeout = [_CountdownTime integerValue]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, );
_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(timeout<=){
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
[VerificationCodeButton setTitle:@"重新获取" forState:UIControlStateNormal];
VerificationCodeButton.userInteractionEnabled = YES;
VerificationCodeButton.alpha = 1.0;
VerificationCodeButton.backgroundColor = [UIColor whiteColor];
});
} else {
NSString *strTime = [NSString stringWithFormat:@"%lds", (long)timeout];
dispatch_async(dispatch_get_main_queue(), ^{
[VerificationCodeButton setTitle:strTime forState:UIControlStateNormal];
VerificationCodeButton.userInteractionEnabled = NO;
VerificationCodeButton.backgroundColor = [UIColor lightTextColor];
});
timeout--;
}
});
dispatch_resume(_timer);
}

iOS 验证码按钮倒计时的更多相关文章

  1. 【积累】发送验证码按钮倒计时js

    注册的时候要发送验证码,就上网研究了一下,写了一个简单点的... jsp页面: <input type="button" id="testbtn" val ...

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

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

  3. iOS 按钮倒计时功能

    iOS 按钮倒计时功能, 建议把按钮换成label,这样会避免读秒时闪烁 __block ; __block UIButton *verifybutton = _GetverificationBtn; ...

  4. iOS点击获取短信验证码按钮

    概述 iOS点击获取短信验证码按钮, 由于 Demo整体测试运行效果 , 整个修改密码界面都已展现, 并附送正则表达式及修改密码逻辑. 详细 代码下载:http://www.demodashi.com ...

  5. ios 简单的倒计时验证码数秒过程实现

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) ...

  6. ios 手机验证码用户注册(倒计时15秒)

    // // ViewController.m // register手机验证码注册 // // Created by zzqqrr on 17/8/28. // Copyright (c) 2017年 ...

  7. js手机短信按钮倒计时

    /*   120秒手机短信按钮倒计时   */    exports.sendmessage = function (name) {        var second = 120; $(name). ...

  8. 移除IOS下按钮的原生样式

    写WAP页面的时候  一定要加上这组样式,以避免在IOS下面按钮被系统原生样式影响 input,textarea {outline-style:none;-webkit-appearance:none ...

  9. 6.短信验证码60s倒计时

    短信验证码60s倒计时 html: <input type="button"  class="btn btn-primary" value="免 ...

随机推荐

  1. .Net Core 中间件之静态文件(StaticFiles)源码解析

    一.介绍 在介绍静态文件中间件之前,先介绍 ContentRoot和WebRoot概念. ContentRoot:指web的项目的文件夹,包括bin和webroot文件夹. WebRoot:一般指Co ...

  2. Python面向对象基础:编码细节和注意事项

    在前面,我用了3篇文章解释python的面向对象: 面向对象:从代码复用开始 面向对象:设置对象属性 类和对象的名称空间 本篇是第4篇,用一个完整的示例来解释面向对象的一些细节. 例子的模型是父类Em ...

  3. VRF在区块链中的应用

    最近区块链领域流行了一种"怪病",许多区块链项目或者设计方案都加入了一个叫做VRFs的算法.那么, (1) 什么是VRFs? (2) VRFs在区块链中解决了什么问题? 本文旨在介 ...

  4. B树与B+详解

    承接上篇SQLite采用B树结构使得SQLite内存占用资源较少,本篇将讲述B树的具体操作(建树,插入,删除等操作).在看博客时,建议拿支笔和纸,一点一点操作,毕竟知识是自己的,自己也要消化的.本篇通 ...

  5. Docker在Windows上运行NetCore系列(一)使用命令控制台运行.NetCore控制台应用

    系列文章:https://www.cnblogs.com/alunchen/p/10121379.html 本篇文章操作系统信息 Windows:Window 10 Visual Studio:201 ...

  6. [转]Angular4首页加载慢优化之路

    本文转自:https://blog.csdn.net/itest_2016/article/details/80048398 Angular是一个比较完善的前端MVC框架,包含了模板,数据双向绑定,路 ...

  7. 第一册:lesson thirty nine.

    原文: Don't drop it! A:What are you going to do with that vase,Penny? B:I am going to put it on the ta ...

  8. 博客使用base64编码图片测试

    为了解决发博客时需要先要上传,所以查了一下这个方法 1.把本地图片转为base64编码的字符串, 网上有很多提供这个功能的网站,转换后像这样 data:image/jpeg;base64,/9j/4A ...

  9. 使用NetDrive将虚拟机映射到本地磁盘,使用smba映射本地磁盘(替代FileZilla)

    使用NetDrive映射到本地磁盘 使用NetDrive软件来替代FileZilla,NetDrive是一个能把FTP空间虚拟成本地硬盘的软件,这样我们就不需要再使用FileZilla来来回拷贝文件了 ...

  10. C-fopen,fwrite,fread,fseek,fgets,popen,access笔记

    FILE * fopen(const char * path,const char * mode); 所需库: <stdio.h> 返回值 FILE是C语言定义的标准数据结构,如果open ...