假设我有3 UIStepper
s
当我更改值1时,其他步进器的值会根据公式更改。
步进器一个值是10.
步进器二值为5.
步进器三值为3.
如果我更改步进器10 +/- 1,它可能会更改步进器2中的值+/- 1。
这可能吗?
答案 0 :(得分:3)
绝对可能。
您可以想象这种情况:
UIStepper *stepperOne = [[UIStepper alloc] initWithFrame:frame];
[stepperOne addTarget:self action:@selector(stepperOneChanged:) forControlEvents:UIControlEventValueChanged];
- (void)stepperOneChanged:(UIStepper*)stepperOne{
//This method would be called on the target of your first stepper on UIControlEventsValueChanged
//Decrease the value by 1
stepperTwo.value --;
//OR
//Increase the value by 1
stepperTwo.value ++;
}
答案 1 :(得分:0)
override func viewDidLoad() {
super.viewDidLoad()
let stepper = UIStepper(frame: CGRect(x: 100, y: 200, width: 0, height: 0))
stepper.wraps = true
stepper.autorepeat = true
stepper.maximumValue = 20
stepper.addTarget(self, action: #selector(stepperValueChanged(_:)), for: .valueChanged)
view.addSubview(stepper)
}
@objc func stepperValueChanged(_ stepper: UIStepper) {
print("Chnaged Value: \(stepper.value)")
stepper.value += 2
print("Chnaged Value: \(stepper.value)")
}