SnappingStepper icon indicating copy to clipboard operation
SnappingStepper copied to clipboard

How to have only Int values in the stepper?

Open davidseek opened this issue 9 years ago • 3 comments

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

davidseek avatar Dec 20 '16 13:12 davidseek

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))"
}

yannickl avatar Dec 31 '16 18:12 yannickl

For Swift 3:

stepper.addTarget(self, action: #selector(stepperValueChanged(_:)), for: .valueChanged)

@objc func stepperValueChanged(_ sender: SnappingStepper) {
    sender.thumbText = "\(Int(sender.value))"
}

ergunkocak avatar Apr 25 '17 08:04 ergunkocak

stepper.addTarget(self, action: "valueChanged:", forControlEvents: .ValueChanged)

func valueChanged(sender: SnappingStepper) {
  stepper.thumbText = "\(stepper.value.rounded())"
}

shiablue avatar Oct 30 '20 01:10 shiablue