我想设置时间倒计时,例如从 60 秒开始,然后经过 59、58、57 等...耗时显示在屏幕底部,如何设置? 请帮助我
提前致谢
最佳答案
你可以像这样使用:
在@interface
上声明一个NSTimer
对象,例如NSTimer *aTimer;
-(void)viewDidLoad
{
aTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(elapsedTime) userInfo:nil repeats:YES];
}
-(void)elapsedTime
{
static int i = 60;
label.text = [NSString stringWithFormat:@"%d",i];
i--;
if(i<0)
{
[aTimer invalidate];
aTimer = nil;
}
}
这里的标签是一个IBOutlet UILabel
,它被设置为接口(interface)。
关于iphone - 如何在 iPhone 中设置倒计时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12543100/