ios – 计时器为3:30分钟,有添加和跳过选项?

ios – 计时器为3:30分钟,有添加和跳过选项?,第1张

概述我是ios中的newbe,所以我想帮助制作一个3:30分钟的计时器,它有两个选项add和skip,它会在计时器到达00:00后消失.请帮助我,我现在处于非常困难的境地. 这是计时器 -(void)updatelable:(NSTimer *)timer { remainingTime=180; for (int i=remainingTime;i==0 ;i--) { 我是ios中的newbe,所以我想帮助制作一个3:30分钟的计时器,它有两个选项add和skip,它会在计时器到达00:00后消失.请帮助我,我现在处于非常困难的境地.

这是计时器

-(voID)updatelable:(NSTimer *)timer {    remainingTime=180;    for (int i=remainingTime;i==0 ;i--) {        NSInteger minutes = floor(*(remainingTime))/ 60;        remainingTime = remainingTime-(minutes*60);        NSInteger seconds = remainingTime;        second.text =[Nsstring stringWithFormat:@"%02ld",seconds];        minute.text =[Nsstring stringWithFormat:@"%02ld",minutes];        timerLabel.text = @"Time up!!";    }    [timer invalIDate];}
解决方法 试试这个

.h文件

{    int counter;    NSTimer timer;}

在.m文件中

- (voID)vIEwDIDLoad {     counter = 210;//total Time     timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(targetmethod:) userInfo:nil repeats:YES];         }-(voID)targetmethod:(NSTimer*)timr{     if(counter == 0)     {         [timer invalIDate]         //set label hIDden here after 3:30 minutes     }     //strTime is string containing remaining time     Nsstring *strTime = [self formatTimeFromSeconds:counter];     counter--;}

对于Label文本调用此方法

-(Nsstring *)formatTimeFromSeconds:(int)numberOfSeconds{    int seconds = numberOfSeconds % 60;    int minutes = (numberOfSeconds / 60) % 60;    int hours = numberOfSeconds / 3600;    //we have >=1 hour => example : 3h:25m    if (hours)        return [Nsstring stringWithFormat:@"%dh:%dm:%ds",hours,minutes,seconds];    //we have 0 hours and >=1 minutes => example : 3m:25s    if (minutes)        return [Nsstring stringWithFormat:@"%dm:%ds",seconds];    //we have only seconds example : 25s    return [Nsstring stringWithFormat:@"%ds",seconds];}
总结

以上是内存溢出为你收集整理的ios – 计时器为3:30分钟,有添加和跳过选项?全部内容,希望文章能够帮你解决ios – 计时器为3:30分钟,有添加和跳过选项?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1027028.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存