gpt4 book ai didi

ios - 使用 UIButton 向 Timer 添加和减少时间

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:55:15 25 4
gpt4 key购买 nike

大家好,我有一个问题,我如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com