iOS 验证码按钮倒计时
在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 验证码按钮倒计时的更多相关文章
- 【积累】发送验证码按钮倒计时js
注册的时候要发送验证码,就上网研究了一下,写了一个简单点的... jsp页面: <input type="button" id="testbtn" val ...
- iOS “获取验证码”按钮的倒计时功能
iOS 的倒计时有多种实现细节,Cocoa Touch 为我们提供了 NSTimer 类和 GCD 的dispatch_source_set_timer方法去更加方便的使用计时器.我们也可以很容易的的 ...
- iOS 按钮倒计时功能
iOS 按钮倒计时功能, 建议把按钮换成label,这样会避免读秒时闪烁 __block ; __block UIButton *verifybutton = _GetverificationBtn; ...
- iOS点击获取短信验证码按钮
概述 iOS点击获取短信验证码按钮, 由于 Demo整体测试运行效果 , 整个修改密码界面都已展现, 并附送正则表达式及修改密码逻辑. 详细 代码下载:http://www.demodashi.com ...
- ios 简单的倒计时验证码数秒过程实现
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) ...
- ios 手机验证码用户注册(倒计时15秒)
// // ViewController.m // register手机验证码注册 // // Created by zzqqrr on 17/8/28. // Copyright (c) 2017年 ...
- js手机短信按钮倒计时
/* 120秒手机短信按钮倒计时 */ exports.sendmessage = function (name) { var second = 120; $(name). ...
- 移除IOS下按钮的原生样式
写WAP页面的时候 一定要加上这组样式,以避免在IOS下面按钮被系统原生样式影响 input,textarea {outline-style:none;-webkit-appearance:none ...
- 6.短信验证码60s倒计时
短信验证码60s倒计时 html: <input type="button" class="btn btn-primary" value="免 ...
随机推荐
- OnlineJudge难度与正确度的相关性检验
本着做题的心态,上了东莞理工学院的 oj 网:在选择难度的时候发现有些题目通过率和难度可能存在着某些关系,于是决定爬下这些数据简单查看一下是否存在关系. 一.新建项目 我是用 Scrapy 框架爬取的 ...
- Java Web中提交表单之后跳转到WebContent目录下的子目录里的jsp文件
最近在做一个系统,需要完成登录动能进行跳转到另一个页面.在这个项目里面,我把 jsp,css,js文件都统一放在 WebContent 目录下的一个 WebPage 里面. 按照以前的习惯,写好了 s ...
- Spring中Bean的生命周期及其扩展点
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/6106456.html Spring中Bean的管理是其最基本的功能,根据下面的图来了解Spr ...
- Java设计模式学习记录-观察者模式
前言 观察者模式也是对象行为模式的一种,又叫做发表-订阅(Publish/Subscribe)模式.模型-视图(Model/View)模式. 咱们目前用的最多的就是各种MQ(Message Queue ...
- c# 图片带水纹波动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 积累一些不太常用的C/C++语言知识(不断更新)
这里积累一些日常编程用得比较少的知识,不断添加. scanf("%c%*c%c",&a,&b); 其中的*表示跳过,本来输入三个数字,结果中间那个读入后被抛弃,a和 ...
- 给大家带来一些 horm的一些知识!
1. form action 提交地址 https://www.baidu.com merhod 提交 方式post get get是在http的url上提交不加密 post加密在http 中 ...
- 快速排序 and 拉格朗日插值查找
private static void QuictSort(int[] zu, int left, int right) { if (left < right) { ; ; ]; while ( ...
- virtualbox中 清理磁盘
1. 碎片整理 windows: 下载 sdelete 工具 执行命令: sdelete –z c:\ Linux: 执行如下命令: sudo dd if=/dev/zero of=/EMPTY bs ...
- Codeforces617E(莫队)
E. XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input ...