这是计时器
-(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分钟,有添加和跳过选项?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)