您好,我正在尝试制作一个简单的倒计时应用程序。
但是我的倒数只有几秒钟,而不是几分钟和几小时。我该怎么做?
最佳答案
创建计时器:
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(Countdown) userInfo:nil repeats: YES];
倒数方法:
-(void) Countdown {
int hours, minutes, seconds;
secondsLeft--;
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
label.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
}
参考:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Timers/Articles/usingTimers.html
关于ios - 如何在NSTimer中显示hh:mm:ss?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23216571/