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定时器, ...
随机推荐
- Rabbitmq交换器Exchange和消息队列
通常我们谈到队列服务, 会有三个概念: 发消息者.队列.收消息者,RabbitMQ 在这个基本概念之上, 多做了一层抽象, 在发消息者和 队列之间, 加入了交换器 (Exchange). 这样发消息者 ...
- bzoj 1070 [SCOI2007]修车——网络流(拆边)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...
- Linux history时间用户ip设置
Linux history时间用户ip设置 在使用linux服务器的时候发生一些不知道谁操作的问题,google一下说history命令可以查看到历史记录,用过之后发现还是不够详细,再g ...
- OPCClient和OPCServer在Windows上运行方式的恩怨
http://www.diangon.com/wenku/PLC/201504/00021970.html 近段时间,遇到不少人都被OPCClient与OPCServer之间的通讯搞得头大,通过几次远 ...
- STM32的启动过程分析
对于stm32的启动过程一直心存疑惑.今天找了很多资料,进行了一个大致的分析. 1.cortex M3的复位过程(来自官方资料) 上述开机启动流程比较详细,内容较为全面,但部分步骤可以省略(红字可省略 ...
- cowboy的get和post的例子
官方get和post的代码是有问题的,1.1下运行crash,这里修改了下,贴代码 创建工程 rebar-creator create-app testCowboy testCowboy_app.er ...
- vue-router规则下 history模式在iis服务器上配置
vue默认模式是hash模式 url地址栏会带有“#”这个字符. 例如:http://www.xxx.com/#/index 感觉和正常的url相比有点丑. 如何让此地址如正常的url一样 官 ...
- POJ1159解题心得
题目:http://poj.org/problem?id=1159 刚开始,从样例的特征去思考.总让我从回文数的角度去思考,想出几个方案,可都用了数据去检验,发现不行.如:ABCDDCB,BACDCA ...
- Windows远程桌面连接CentOS 7
1. 安装tigervnc-server yum install tigervnc-server 2. 设置vncserver服务器 将默认提供的文件复制到/etc/systemd/system,命令 ...
- Long.parseLong(String s) 其中s必须是数字形式的字符串,才能运用该函数转化为长整型。
public class ConverTo { public static void main(String [] args) { String numberIn =args[0]; convertN ...