@property (nonatomic ,assign)NSInteger secondsCountDown;//倒計(jì)時(shí)的總時(shí)間
@property (nonatomic ,strong)NSTimer *countDownTimer;//定時(shí)器
//寫入BUT點(diǎn)擊事件
-(void)buttonDidClock{
//設(shè)置倒計(jì)時(shí)總時(shí)長
self.secondsCountDown = 60;
self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startTimeNSTimer) userInfo:nil repeats:YES];
[self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新發(fā)送",(long)self.secondsCountDown] forState:UIControlStateNormal];
}
//使用NSTimer實(shí)現(xiàn)倒計(jì)時(shí)
- (void)startTimeNSTimer
{
self.secondsCountDown -- ;
self.capthaButton.userInteractionEnabled = NO;
[self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新發(fā)送",(long)self.secondsCountDown] forState:UIControlStateNormal];
if (self.secondsCountDown == 0) {
[self.countDownTimer invalidate];
self.capthaButton.userInteractionEnabled = YES;
[self.capthaButton setTitle:@"重新發(fā)送驗(yàn)證碼" forState:UIControlStateNormal];
}
}