Once a IBAction is pressed, I want a counter which counts up.
But in this form
00:00:00
Hours:minutes:seconds
This is the code so far:
-(void)countUp {
mainInt += 1;
seconds.text = [NSString stringWithFormat:@"%02d", mainInt];
}
This only counts up in 00 format
Thanks for the help!
Just do the appropriate math to break the count up into its constituent parts:
For the sake of readability, it’d be nice to replace that inline math with macros or functions, for example:
Often when implementing this sort of display, you don’t want the colons to jump around as the elapsed time changes. Many fonts have fixed-width numerals, so it’s not always a problem, but you might want to use three separate labels for the hours, minutes, and seconds, with unchanging labels in between for the colons.
Another approach to the math above is to store the seconds, minutes, and hours in three variables instead of one, and just be careful to increment minutes and reset seconds when seconds hit 60, and so on. To make this easier to use, encapsulate it in a class, like: