Can you set a default/current value for UIStepper

2019-07-28 08:22发布

问题:

I tried to do something like this in the viewDidLoad method:

 self.myStepper.value = 10.0;

But it's not working. I've googled and googled and I can't find any answers to this. It seems so easy for a slider, but can you do it with a stepper as well?

回答1:

Stepper values need to be within bounds of min and max, or like in the comments to your question they get pushed to either the min or max. Always check Apple's Reference docs.
Reference: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIStepper_Class/Reference/Reference.html



回答2:

I figured it out, I simply forgot to init the steppers in the viewDidLoad method. Sorry guys!



回答3:

We can set the Value for the Stepper using the Below Syntax,

[your_stepper_name setValue:your_stepper_value];

ex:

[stepper setValue:10];