iOS发送验证码倒计时功能的实现
2015-06-13 20:46
791 查看
1. viewDidload里配置倒计时Timer
//set the countdown timer self.seconds = 60; self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod) userInfo:nil repeats:YES];
2. 每秒钟触发一次Timer
-(void)timerFireMethod { if (self.seconds == 1) { [self.countdownTimer invalidate]; self.countdownTimerLabel.text = @""; self.seconds = 60; [self.sendAgainButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; self.sendAgainButton.enabled = YES; }else{ self.seconds--; self.countdownTimerLabel.text = [NSString stringWithFormat:@"(%lu)",(unsigned long)self.seconds]; [self.sendAgainButton setTitleColor:[UIColor colorWithRed:189 / 255.f green:189 / 255.f blue:189 / 255.f alpha:1.0] forState:UIControlStateNormal]; self.sendAgainButton.enabled = NO; } }
3. Timer的release方法
- (void)releaseTimer { if (self.countdownTimer) { if ([self.countdownTimer respondsToSelector:@selector(isValid)]) { if ([self.countdownTimer isValid]) { [self.countdownTimer invalidate]; self.seconds = 60; } } } }
相关文章推荐
- iOS调节系统音量
- iOS开发--@property属性的使用
- IOS笔记047-代理传值和block传值
- IOS笔记047-代理传值和block传值
- torch-ios框架XCODE使用备忘
- iOS判断字符串是否符合格式要求
- ios获取当前年月日和星期
- iOS汉字识别改进算法
- iOS Widget简单使用
- iOS多线程编程之NSThread的使用
- IOS 四种保存数据的方式
- [iOS]Error Domain=NSURLErrorDomain Code=-1005 “The network connection was lost.”
- IOS中宏的高级使用
- ios8.0下CLLocationManager定位服务需要授权了
- IOS集成支付宝支付方法和问题的总结
- iOS程序进入后台后仍运行定时器
- iOS简单的手写汉字识别
- iOS如何把所有界面的状态栏的字体颜色都设置为白色
- iOS 的 XMPPFramework 简介
- iOS-二维码