iOS倒计时
现在开发基本上都有发送验证码,倒计时,下面说一种
#import <UIKit/UIKit.h> @interface UIButton (CountDown)
-(void)startTime:(NSInteger )timeout title:(NSString *)tittle waitTittle:(NSString *)waitTittle;
@end
#import "UIButton+CountDown.h" @implementation UIButton (CountDown)
-(void)startTime:(NSInteger )timeout title:(NSString *)tittle waitTittle:(NSString *)waitTittle{
__block NSInteger timeOut=timeout; //倒计时时间
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(timeOut<=){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self setTitle:tittle forState:UIControlStateNormal];
self.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60;
int seconds = timeOut % ; NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
NSLog(@"____%@",strTime);
[self setTitle:[NSString stringWithFormat:@"%@%@",strTime,waitTittle] forState:UIControlStateNormal];
self.userInteractionEnabled = NO; }); timeOut--; }
});
dispatch_resume(_timer); }
@end
iOS倒计时的更多相关文章
- iOS 倒计时NSTimer
		
项目中可能会遇到有些倒计时的地方 比方 手机验证的时候,验证码一般都会有一个时间限制,此时在输入验证码的地方就须要展示一个倒计时 详细实现方式是使用了iOS 自带的 NSTimer 上代码 首先新建 ...
 - 小程序实现倒计时:解决ios倒计时失效(setInterval失效)
		
在使用之前需要先在page页引入wxTimer.js文件(这里我将文件放在/utils) let timer = require('../../utils/wxTimer.js'); 然后就可以使用啦 ...
 - iOS 倒计时
		
// // RootViewController.m // MyTimerDemo // // Created by huluo on 1/21/14. // Copyright (c) 2014 b ...
 - iOS 倒计时的一种实现
		
1.view [self performSelectorInBackground:@selector(thread) withObject:nil]; - (void)thread { ;i>= ...
 - iOS - 倒计时封装
		
+(NSString *)countdownStartTime:(NSString *)startTime{ NSString *TIME = [startTime substringToIndex: ...
 - iOS倒计时button闪烁
		
v _button.titleLabel.text = [NSString stringWithFormat:@"%d后重发",t]; [_button setTitle:[NSS ...
 - iOS炫酷动画图案、多种选择器、网络测速、滑动卡片效果等源码
		
iOS精选源码 对网络进行测速 自实现大标题,配合原生骨架屏demo 简单方便的pickerVIew记录数据 LZPickerView 科技风绘制组件,简单快速"画"出炫酷图案 R ...
 - iOS “获取验证码”按钮的倒计时功能
		
iOS 的倒计时有多种实现细节,Cocoa Touch 为我们提供了 NSTimer 类和 GCD 的dispatch_source_set_timer方法去更加方便的使用计时器.我们也可以很容易的的 ...
 - iOS 短信验证码倒计时按钮的实现
		
验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...
 
随机推荐
- 最最基本的SQL常用命令
			
2015-12-01 18:08:52 1.启动/关闭mysql 开始菜单搜索cmd,右击,以管理员身份运行,输入net start mysql启动mysql,输入net stop mysql关闭my ...
 - xunsearch之php索引维护(四)
			
1.添加文档 $xs = new XS('njw'); $index = $xs->index; $data = array( 'pid' => 234, // 此字段为主键,必须指定 ' ...
 - 1-3 superset数据模型
			
在models.py中大部分的class对应数据库中的表,那么我们就从AuditMixinNullable这个类开始我们的模型解析. AuditMixin:这个类是FAB(Flask AppBuil ...
 - snmp安装zabbix
			
zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题. zabbix由2部分构成,zabbix server与可选组件zabbix ...
 - boost  编译 安装
			
首先到 boost.org 下载 boost_1_54_0.tar.gz 上传到 linux 环境下 解压缩 给解压缩出来的文件斌权限 chmod 777 ./* 执行己写好的 shell脚本 boo ...
 - jQuery实现页面监听(某一个值发生改变时触发)
			
使用jQuery实现页面中监听 页面中某一个值(如input输入框)发生改变时触发. <html> <head> <title>RunJS</title& ...
 - CXF+Spring搭建webservice服务
			
Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS .这些 Services 可以支持多 ...
 - MySQL 5.7.18 主从复制 Error1205
			
从库报 error 1205 1.mysql报错信息 [root@slave2(35.102) ~]# mysql -uroot -p Enter password: Welcome to the M ...
 - Windows下编译sqlite3
			
一.下载 sqlite-amalgamation-3240000:sqlite源代码,主要需要头文件sqlite3.h sqlite-dll-win32-x86-3240000.zip:sqlite3 ...
 - ListView下拉刷新,上拉自动加载更多
			
下拉刷新,Android中非常普遍的功能.为了方便便重写的ListView来实现下拉刷新,同时添加了上拉自动加载更多的功能.设计最初是参考开源中国的Android客户端源码.先看示例图. ...