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

标签 ios objective-c uibutton nstimer

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

相关文章:

ios - 如何将 userdefault 值转换为 URL?

ios - Swift 使用来自 Parse 的数据解包 Optional 值时出现 fatal error

ios - 交互式过渡不是线性的

iOS 创建 PDF 发票

ios - UIButton 处于循环中,事件仅在第一个元素上触发

objective-c - XCode 4、ParseKit 和存档目标

ios - UICollectionView 异步更新大小

ios - 使 swift 类符合定义属性的 objective c 协议(protocol)

objective-c - 使用 UITapGestureRecognizer 显示/隐藏菜单

ios - 发送到实例的 Swift 无法识别的选择器