The default behaviour of UISlider
is that its thumb isn't centered on start/end of track. Like below:
I would like to modify it's behaviour to get:
where thumb's center can be positioned on start or end.
I have tried to cover start/end with empty UIView
. Effect is that is look almost ok, but thumb has dropshadow that reveals my hack in some positions (which I can live with), however my hacky view covers a little the thumb and captures it's touch event (even when user interactions are disabled).
So I guess I would need to pack my hacky view between thumb and track. Possibly without manipulating its internal views. Any ideas?
UISlider class has a method thumbRect(forBounds:trackRect:value:) that you can override to control the drawing rectangle for the slider’s thumb image. So assuming that this space is 5 points (might vary depending on the thumb image you are using) we can do the following:
UISlider
and overridethumbRect(forBounds:trackRect:value:)
to hook ourselves into the processThe complete code should be like the following:
Swift 5 version for lazy ones like me :)