yonat / MultiSlider

UISlider clone with multiple thumbs and values, range highlight, optional snap intervals, optional value labels, either vertical or horizontal.
MIT License
494 stars 113 forks source link

Set predefined value of thumbs #53

Closed LoopingLouieX closed 4 years ago

LoopingLouieX commented 4 years ago

Is there a possibility to set a value of each thumb ?

With the UISlider module you can move the thumb to a predefined value with slider.setValue(value, animated: true)

yonat commented 4 years ago

Not animated, but you can do this:

var sliderValue = slider.value
slider.value[0] = 17
slider.value = sliderValue
LoopingLouieX commented 4 years ago

Thanks for the answer, that's exactly what I've looked for! Isn't it not enough to set: slider.value[0] = 17 ?

Also I wanted to ask which value type is needed here because if I'm typing in the number directly as the example above it's working. But if I'm declare a variable first, it's not (example below). var number = 17 slider.value[0] = number ==> Value of type 'MultiSlider?' has no subscripts

Thanks!

yonat commented 4 years ago

Yes, slider.value[0] = 17 will work fine after either setting an initial value or a thumbCount. Otherwise the value array is empty.

value is an array of CGFloat, but in starts as empty. To avoid the error your getting, first set:

slider.value = [17]

Or alternatively:

slider.thumbCount = 1