Time Counter
In most of the time, we need to display the timer in UIView for the count down the time. for this, we need to make UILabel and at the time of class loading we need to define seconds.
let seconds = 3600 for 1 hour.
here is a code snippet.
declare in viewDidLoad function
1 |
[self countdownTimer]; |
define countdownTimer function.
1 2 3 |
-(void)countdownTimer { timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES]; } |
here this function calls updateCounter function in every second. so you can update your UILabel .
1 2 3 4 5 6 7 8 9 |
- (void)updateCounter:(NSTimer *)theTimer { if(secondsLeft > 0 ) { secondsLeft -- ; hours = secondsLeft / 3600; minutes = (secondsLeft % 3600) / 60; seconds = (secondsLeft %3600) % 60; (Your Label)timerLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds]; } } |
Now manges your counter according to your need.