SnappingStepper
SnappingStepper copied to clipboard
How to have only Int values in the stepper?
I have a stepper from 1 to 10.
The steps are Doubles. Published in the thumbText.
I want them to be Integer. How would I do that?
Thanks in advance
Hi,
Sorry for the late, I was in holidays and no time to answer before.
If the stepper value is round (i.e. value % 1 == 0) it would display the step as an integer. But if it does not work you can set its value inside a valueChanged: action:
stepper.addTarget(self, action: "valueChanged:", forControlEvents: .ValueChanged)
func valueChanged(sender: AnyObject) {
stepper.thumbText = "\(Int(stepper.value))"
}
For Swift 3:
stepper.addTarget(self, action: #selector(stepperValueChanged(_:)), for: .valueChanged)
@objc func stepperValueChanged(_ sender: SnappingStepper) {
sender.thumbText = "\(Int(sender.value))"
}
stepper.addTarget(self, action: "valueChanged:", forControlEvents: .ValueChanged)
func valueChanged(sender: SnappingStepper) {
stepper.thumbText = "\(stepper.value.rounded())"
}