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)
}
A UISlider is a control that allows the user to select a value from a range of values horizontally by dragging the thumb to the position desired. Some use cases where a UISlider is used: Changing the Volume. Changing the Brightness. Changing the current seek of the Video.
If you try to programmatically set a slider's current value to be below the minimum or above the maximum, it's set to the minimum or maximum instead. However, if you set the value beyond the range of the minimum or maximum in Interface Builder, the minimum or minimum values are updated instead.
Enter Swift as Language and choose Next. Go to the Storyboard and drag a Slider to the main view and span its width to the width of the main View. Select the slider and go to the Attributes inspector. Under the slider section change the maximum value to 100 and change the current value to 0.
Overview. A slider consists of a “thumb” image that the user moves between two extremes of a linear “track”. The ends of the track represent the minimum and maximum possible values. As the user moves the thumb, the slider updates its bound value.
If you want your Slider to position only at the steps do:
@IBAction func ringVolumeSliderChange(_ sender: UISlider)
{
sender.setValue(sender.value.rounded(.down), animated: true)
print(sender.value)
}
In this example, I assume you've set min and max values. Now the slider jumps from position to position as the user slides around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With