Implementing steps/snapping UISlider

后端 未结 6 1084
悲哀的现实
悲哀的现实 2020-12-23 02:07

I am trying to implement some form of snapping or steps with the UISlider. I have written the following code but it does not work as smooth as I hoped for. It works, but whe

6条回答
  •  借酒劲吻你
    2020-12-23 02:37

    Another Swift approach is to do something like

    let step: Float = 10
    @IBAction func sliderValueChanged(sender: UISlider) {
      let roundedValue = round(sender.value / step) * step
      sender.value = roundedValue
      // Do something else with the value
    
    }
    

提交回复
热议问题