Adding and decreasing time with UIButton to Timer
Hello everyone, I have a question, how can I add and decrease time using UIButton on timer, for example if I have a minus and plus button and timer time.
Thank.
+3
Tcacenco daniel
source
to share
2 answers
-(void)viewDidLoad{
UIButton *buttonPlus = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *buttonMinus = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonPlus addTarget:self action:@selector(addTime) forControlEvents:UIControlEventTouchUpInside];
[buttonMinus addTarget:self action:@selector(removeTime) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonMinus];
[self.view addSubview:buttonPlus];
}
-(void) addTime {
[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:secondsToAdd]];
}
-(void) removeTime {
[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:-secondsToAdd]];
}
+2
BoilingLime
source
to share
you can add time to NSTimer using this:
[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:secondsToAdd]];
You can reduce the time to NSTimer using:
[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:-secondsToDecrease]];
Hope this helps!
+2
cris
source
to share