2

Let's say I have 3 UISteppers.
When I change the value of one, the values of the other steppers change based on a formula.

Stepper one value is 10.
Stepper two value is 5.
Stepper three value is 3.

If I change stepper 10 +/- 1, it might change the value in stepper two +/- one.

Is this possible?

Paul S.
  • 1,342
  • 4
  • 22
  • 43

2 Answers2

3

It is absolutely possible.

You can imagine this scenario:

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 ++;
}
Zebs
  • 5,378
  • 2
  • 35
  • 49
  • can I say stepperTwo.value = 10; for example, as my test's come back as NULL. workOutLength = classLength - (warmUpLength + coolDownLength); stepperWorkOutLength.value = workOutLength; (How the heck do add code to a reply, every time I hit enter it updates the post :( – Paul S. Mar 09 '12 at 02:37
  • you can put it in between two: ` What is returning NULL? And Yes, you can set the value to nay value between the minimum and maximum value – Zebs Mar 09 '12 at 02:51
0

Swift 4.2

 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)")
    
}
Community
  • 1
  • 1
Yogendra Singh
  • 2,063
  • 25
  • 20