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="免 ...
随机推荐
- git 下载部分目录
需求 github上整个工厂比较大,下起来费劲,如何只下载一个单独的文件件呢? 方法一 以:https://github.com/eugenp/tutorials为例,下载其中的 spring-kaf ...
- openssl dhparam(密钥交换)
openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html openssl dhparam用于生成和管理dh文件.dh(Diffie-H ...
- JavaScript 二进制转文件
关于在javascript下,如何将二进制转换成相应的文件并下载. 首先, 我们需要得到二进制的数据以及相应的文件格式,没有相应的格式也可以,可以通过二进制来判断,但相对会麻烦很多,所以建议可以要求后 ...
- 从零开始学安全(九)●OSI参考模型分层
主要分为7层和网络7层模型一样 物理层主要传输数据比特流 可以理解信号 数据链路层 逻辑层 像是交换机 网络层 又交换机发送到路由器 应用层 应用通信
- python中的property属性
目录 1. 什么是property属性 2. 简单的实例 3. property属性的有两种方式 3.1 装饰器方式 3.2 类属性方式,创建值为property对象的类属性 4. property属 ...
- MySQL事务(学习笔记)
MySQL事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数据库操作语句就构成一个事 ...
- virtualbox中设置u盘启动
1.在磁盘管理中查看u盘的磁盘号X 2.管理员运行cmd,进入virtualbox目录 3.运行命令: VBoxManage internalcommands createrawvmdk -filen ...
- mysql用户授权、数据库权限管理、sql语法详解
mysql用户授权.数据库权限管理.sql语法详解 —— NiceCui 某个数据库所有的权限 ALL 后面+ PRIVILEGES SQL 某个数据库 特定的权限SQL mysql 授权语法 SQL ...
- 抛弃console.log(),拥抱浏览器Debugger
译者按: 切换成本真的不高,建议使用开发者工具来Debug! 原文:How to stop using console.log() and start using your browser's deb ...
- linux学习笔记-时间配置综述
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.时间类型分为: 1.网络时间(设置时区,ntp服务器同步的时间) 2.系统时间,当前系统所显示的时间 3.硬件(RTC)时间 ...