//验证码时间
@property (nonatomic,strong)NSTimer *timer;
//开始计时
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(Countdown) userInfo:nil repeats:YES];
//倒计时
- (void)Countdown
{
static NSInteger time = 59;
self.captchaButton.userInteractionEnabled = NO;
self.captchaButton.alpha = 0.6;
if (time > -1) {
NSString *number = [NSString stringWithFormat:@"%ld",(long)time];
[_captchaButton setTitle:number forState:UIControlStateNormal];
} else {
[_captchaButton setTitle:@"获取" forState:UIControlStateNormal];
self.captchaButton.userInteractionEnabled = YES;
self.captchaButton.alpha = 1;
[_timer invalidate];//停止计时器
_timer = nil;//重置计时器
time = 60;
}
time --;
}
[timer setFireDate:[NSDate date]]; //继续。
[timer setFireDate:[NSDate distantPast]];//开启
[timer setFireDate:[NSDate distantFuture]];//暂停
网友评论