How do I have my UISlider go from 1-100 in increments of 5?
For anyone looking for the Swift syntax...
override func viewDidLoad() {
super.viewDidLoad()
mySlider.addTarget(self, action: "sliderValueDidChange:", forControlEvents: .ValueChanged)
}
func sliderValueDidChange(sender:UISlider!)
{
//Set value to the nearest 5...
print((Float)((Int)((sender.value + 2.5) / 5) * 5))
sender.setValue((Float)((Int)((sender.value + 2.5) / 5) * 5), animated: false)
}
Alternatively, just create an Action function with the Assistant Editor (what I did ultimately)...
@IBAction func mySliderValueChanged(sender: UISlider) {
//Set value to the nearest int
sender.setValue(Float(roundf(sender.value)), animated: false)
}