5

Hope someone can help me. Im trying to make a UISlider with step value from 1 to 5 in Swift

My code are:

@IBAction func yearChange(sender: UISlider) {

    let step: Float = 1
    let currentValue = round(sender.value / step) * step
    print("\(currentValue) year")

}
Flemming Ovesen
  • 305
  • 2
  • 4
  • 15

2 Answers2

11

i solved the issue with this code :

let step: Float = 1
let roundedValue = round(sender.value / step) * step
sender.value = roundedValue
aturan23
  • 4,798
  • 4
  • 28
  • 52
Flemming Ovesen
  • 305
  • 2
  • 4
  • 15
0

hope this help

let slider = UISlider()
let total: Float = 5
slider.maximumValue = total
slider.minimumValue = 1

@IBAction func yearChange(sender: UISlider) {
    
    let step: Float = 1
    let currentValue = round((sender.value - sender.minimumValue) / step)
    print("\(currentValue) year")
    
}
aturan23
  • 4,798
  • 4
  • 28
  • 52
Ethan
  • 461
  • 4
  • 13