您好,我正在尝试制作一个简单的倒计时应用程序。
但是我的倒数只有几秒钟,而不是几分钟和几小时。我该怎么做呢?
创建计时器:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句