@interface ViewController ()
{
NSInteger timeCount;//秒数
}
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, copy) NSTimer *timer;
@end
timeCount = 300;//倒计时秒数
// NSString *hour = [NSString stringWithFormat:@"%02ld",secondsCountDown/3600];//时
NSString *minute = [NSString stringWithFormat:@"%02ld",(timeCount%3600)/60];//分
NSString *second = [NSString stringWithFormat:@"%02ld",timeCount%60];//秒
_label.text = [NSString stringWithFormat:@"%@:%@",minute,second];
_timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(countDownAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
- (void)countDownAction {
timeCount--;
NSLog(@"%ld",(long)timeCount);
NSString *minute = [NSString stringWithFormat:@"%02ld",(timeCount%3600)/60];//分
NSString *second = [NSString stringWithFormat:@"%02ld",timeCount%60];//秒
_label.text = [NSString stringWithFormat:@"%@:%@",minute,second];
if (timeCount == 0) {
[_timer invalidate];
}
}