我想让 UILabel 显示计时器的当前进度。现在要获取当前剩余时间,我调用[timer1 timeLeft];
它返回一个int
. 通过这种方式,我可以一次更新标签一次。我可以通过什么方式mainLabel
不断更新标签 ( ) 以便它始终显示当前计时器进度,同时在某种程度上节省资源?
感谢你的帮助!
我想让 UILabel 显示计时器的当前进度。现在要获取当前剩余时间,我调用[timer1 timeLeft];
它返回一个int
. 通过这种方式,我可以一次更新标签一次。我可以通过什么方式mainLabel
不断更新标签 ( ) 以便它始终显示当前计时器进度,同时在某种程度上节省资源?
感谢你的帮助!
将以下代码用于倒数计时器。
dblElapsedSeconds=0.0; //Declare this in header
tmrElapsedTime = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateElapsedTime) userInfo:nil repeats:YES]; //Declare timer variable in header
-(void)updateElapsedTime
{
dblElapsedSeconds += 1;
//double seconds = [[NSDate date] timeIntervalSinceDate:self.startTime];
int hours,minutes, lseconds;
hours = dblElapsedSeconds / 3600;
minutes = (dblElapsedSeconds - (hours*3600)) / 60;
lseconds = fmod(dblElapsedSeconds, 60);
[lblTimeElapsed setText:[NSString stringWithFormat:@"%02d:%02d",minutes, lseconds]];
}