Search code examples
objective-ccocoa-touchuiviewuislider

Set thumb image position of UISlider in iOS


Is there any way to set thumb image position of UISlider irrespective of slider value? For example, slider value can be anything between 0 - 100, but i want to keep thumb image at position 20. Is it possible to achieve this with the default UISlider rather than creating a custom slider? Thanks for your answer.


Solution

  • You would need to subclass UISlider and override thumbRectForBounds:trackRect:value: to return a custom frame for the thumb. Not sure what purpose this would serve by your description though...


    Based on your comment, the above is not the approach you want to take. Instead, your view controller should add itself as the target for the valueChanged (UIControlEventValueChanged) actions coming from the slider.

    In this method, determine the appropriate rounded value from the slider's value and then use setValue:animated: to move the slider thumb to the appropriate place.