NSTimer 倒计时
来源:互联网 发布:淘宝网退回旧版本 编辑:程序博客网 时间:2024/06/10 09:33
#pragma mark - 倒计时- (void)startCount{ /** * 添加定时器 */ self.currentCountDown = 120; self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; [self.timer fire];}- (void)countDown{ if (self.currentCountDown >0) { //设置界面的按钮显示 根据自己需求设置 [self.captchaBtn setTitle:[NSString stringWithFormat:@"(%ld)重新获取",(long)self.currentCountDown] forState:UIControlStateNormal]; //self.captchaBtn.enabled = NO; self.currentCountDown -= 1; }else{ [self removeTimer]; }}/** * 移除定时器 */- (void)removeTimer{ self.currentCountDown = 0; [self setCaptchaEnable:YES]; [self.timer invalidate]; self.timer = nil;}//因为iOS 7下 按钮 enabled= NO, 不能设置文字#pragma mark - 设置按钮状态- (void)setCaptchaEnable:(BOOL)enabled{ //可以按 if (enabled) { self.captchaBtn.userInteractionEnabled = YES; [self.captchaBtn setBackgroundImage:[UIImage imageNamed:@"back_red"] forState:UIControlStateNormal]; [self.captchaBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; }else{ self.captchaBtn.userInteractionEnabled = NO; [self.captchaBtn setBackgroundImage:[UIImage imageNamed:@"back_gray"] forState:UIControlStateNormal]; }}
0 0
- NSTimer 倒计时
- NSTimer倒计时
- 使用NSTimer实现倒计时
- 使用NSTimer实现倒计时
- 使用NSTimer实现倒计时
- 使用NSTimer实现倒计时
- 使用NSTimer实现倒计时
- iOS NSTimer 实现倒计时
- NSTimer写一个倒计时
- 使用NSTimer实现倒计时
- iOS 之NSTimer倒计时
- iOS 倒计时NSTimer
- NStimer 倒计时实现
- 基于NSTimer的倒计时
- NSTimer+倒计时功能实现
- NSTimer+倒计时功能实现
- iphone--使用NSTimer实现倒计时
- NSTimer实现读秒、倒计时等周期性操作
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 怎样写出优秀的研究论文?
- 文章标题
- OC中属性self.a与_a访问的区别
- 如何使用Android Studio把自己的Android library分享到jCenter和Maven Central
- NSTimer 倒计时
- Jedis的八种实现方式
- Android动画使用中的若干问题【持续更新】
- 【数据库】数据库负载均衡、读写分离技术
- Java删除服务器上的文件
- Javascript面向对象编程(三)
- 第八周项目(2)-游戏中的角色类增强版
- Spark RDD解密
- 实用简介:MQTT协议及其在物联网中的应用