Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add and decrease time with UIButton to Timer

Hello everyone i have a question how i can add and decrease time with UIButton to timer for example if i will have button with minus and plus and time at timer.

Thank you.

like image 280
Tcacenco Daniel Avatar asked Aug 23 '26 04:08

Tcacenco Daniel


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]];
}
like image 87
BoilingLime Avatar answered Aug 26 '26 03:08

BoilingLime


you could add time to a NSTimer using this:

[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:secondsToAdd]];

You could decrease time to a NSTimer using:

[yourTimer setFireDate:[[yourTimer fireDate] dateByAddingTimeInterval:-secondsToDecrease]];

Hope this helps!

like image 32
cris Avatar answered Aug 26 '26 04:08

cris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!