Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CountDown Timer ios tutorial? [closed]

I'm making an application where the exams is going on, so when exam start the, time should start with that. For example 30 minutes and it should reduce like 29:59.

How can I implement this?

Can anyone please give me a sample example or a easy step by step tutorial that i can follow?

like image 889
zeeshan shaikh Avatar asked Jun 17 '13 10:06

zeeshan shaikh


People also ask

How do I set a timer on my Iphone countdown?

To do this, in the Clock app, tap on Timer at the bottom-right corner of the screen to bring up the Timer screen. You can scroll the Hours and Minutes wheels onscreen to set the amount of time you want to count down to.

Can you put a countdown on your iphone lock screen?

Features: iOS 14 WIDGETS: Now you can count down the days to your event right from your home screen! Just long hold an empty area on your home screen and tap the "+" in the corner to get started. DRAG the Countdown DISPLAY wherever you want.

How do I remove countdown timer?

Open the start menu. and select Special > Countdown timer. In the overview, select the countdown timer that you want to delete and click Delete. Click Delete countdown timer.


1 Answers

This code is used to create a countdown timer.

Code for .h file.

@interface UIMyContoller : UIViewController {  NSTimer *timer;     IBOutlet UILabel *myCounterLabel; }  @property (nonatomic, retain) UILabel *myCounterLabel;  -(void)updateCounter:(NSTimer *)theTimer; -(void)countdownTimer;  @end 

Code for .m file.

@implementation UIMyController @synthesize myCounterLabel;  int hours, minutes, seconds; int secondsLeft;  - (void)viewDidLoad {     [super viewDidLoad];      secondsLeft = 16925;     [self countdownTimer]; }  - (void)updateCounter:(NSTimer *)theTimer {     if(secondsLeft > 0 ) {         secondsLeft -- ;         hours = secondsLeft / 3600;         minutes = (secondsLeft % 3600) / 60;         seconds = (secondsLeft %3600) % 60;         myCounterLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];     } else {         secondsLeft = 16925;     } }  -(void)countdownTimer {      secondsLeft = hours = minutes = seconds = 0;     if([timer isValid]) {         [timer release];     }     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];       timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];     [pool release]; } 

Hope this helps you out.

like image 118
Adrian P Avatar answered Oct 15 '22 02:10

Adrian P