@interface ViewController ()
{
NSInteger timeCount;//秒數(shù)
}
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, copy) NSTimer *timer;
@end
timeCount = 300;//倒計(jì)時(shí)秒數(shù)
// NSString *hour = [NSString stringWithFormat:@"%02ld",secondsCountDown/3600];//時(shí)
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];
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者