ios - How to display hh:mm:ss in NSTimer? -
hello i'm trying make simple countdown app.
however countdown in seconds , not in minutes , hours. how make such?
create timer:
timer = [nstimer scheduledtimerwithtimeinterval: 1.0 target:self selector:@selector(countdown) userinfo:nil repeats: yes];
countdown method:
-(void) countdown { int hours, minutes, seconds; secondsleft--; hours = secondsleft / 3600; minutes = (secondsleft % 3600) / 60; seconds = (secondsleft %3600) % 60; label.text = [nsstring stringwithformat:@"%02d:%02d:%02d", hours, minutes, seconds]; }
reference : https://developer.apple.com/library/ios/documentation/cocoa/conceptual/timers/articles/usingtimers.html
Comments
Post a Comment