大家好,我有一个问题,我如何使用 UIButton 添加和减少计时器的时间,例如,如果我有带有减号和加号的按钮以及计时器的时间。
谢谢。
最佳答案
-(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]];
}
关于ios - 使用 UIButton 向 Timer 添加和减少时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26261143/