核心代码:
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(start:) userInfo:nil repeats:YES];
-(void)start:(NSTimer *)timer{
seconds ++;
self.timerLabel.text = [NSString stringWithFormat:@"%ds",seconds];
//到达指定时间暂停
if (seconds == _endTime) {
self.myTimer.fireDate = [NSDate distantFuture];
self.startBtn.selected = YES;
}
}
demo地址:https://github.com/DavieDang/TimerDemo
有帮助到的同学,点击喜欢或收藏一下,谢谢了!