60s倒计时

2017-02-22  本文已影响10人  onlyyourself

@property (nonatomic ,assign)NSInteger secondsCountDown;//倒计时的总时间
@property (nonatomic ,strong)NSTimer *countDownTimer;//定时器

//写入BUT点击事件
-(void)buttonDidClock{
//设置倒计时总时长
self.secondsCountDown = 60;
self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startTimeNSTimer) userInfo:nil repeats:YES];
[self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新发送",(long)self.secondsCountDown] forState:UIControlStateNormal];
}

//使用NSTimer实现倒计时

{
self.secondsCountDown -- ;
self.capthaButton.userInteractionEnabled = NO;
[self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新发送",(long)self.secondsCountDown] forState:UIControlStateNormal];
if (self.secondsCountDown == 0) {
[self.countDownTimer invalidate];
self.capthaButton.userInteractionEnabled = YES;
[self.capthaButton setTitle:@"重新发送验证码" forState:UIControlStateNormal];
}

}

上一篇下一篇

猜你喜欢

热点阅读