Search code examples
iosswiftuislider

How can I restrict iOS slider value to an integer?


I have a horizontal UISlider to control the volume from 1 to 16 as min and max value, but it's returning float values when I do print().

How can I restrict the UISlider value to an integer?

@IBOutlet var ringValue: UISlider!

@IBAction func ringVolumeSliderChange(_ sender: UISlider)
{
    print(sender.value)
}

Solution

  • @IBAction func SliderValueChanged(_ sender: UISlider) {
        showValueSlider.text = String(format: "The value is:%i",Int(sender.value))
    }