9

我设置了计时器代码,而且都是犹太教,但我希望我的标签显示“分钟:秒”而不是仅仅显示秒。

-(void)countDown{

    time -= 1;

    theTimer.text = [NSString stringWithFormat:@"%i", time];

    if(time == 0)
    {
    [countDownTimer invalidate];
    }
}

我已经将“时间”设置为 600 或 10 分钟。但是,我希望显示器显示 10:59、10:58 等,直到它达到零。

我该怎么做呢?

谢谢!

4

2 回答 2

19
int seconds = time % 60;
int minutes = (time - seconds) / 60;
theTimer.text = [NSString stringWithFormat:@"%d:%.2d", minutes, seconds];
于 2010-04-13T03:16:30.930 回答
0

到那时,我对第一个答案进行了一些升级,它消除了与NSInteger和相关的冲突int

NSInteger secondsLeft = 987;
int second = (int)secondsLeft % 60;
int minutes = ((int)secondsLeft - second) / 60;
theTimer.text = [NSString stringWithFormat:@"%02d:%02d", minutes, second]];
于 2016-07-26T15:26:01.337 回答