How to add "knots" to a UISlider?
I am wanting to add markers for certain points along a UISlider. It will have the appearance of knots on the slider track. When the user clicks on a knot, the slider value is set to that value and the thumb goes to that point.
I have currently added image buttons over the 开发者_如何转开发slider, but because of z position the thumb travels under the knots instead of on top. The knots should be over the track but under the thumb.
Does anyone know the best way to achieve this effect?
I think I have come up with a solution. Use 2 UISliders. Put my original slider with the custom track images down. Change it's thumb to be an invisible PNG. But the image buttons on top of this slider. Then add a 2nd slider with an invisible track on top of that. This way the track comes from the bottom slider while the thumb comes from the top.
Now, next question: how is the best way to keep these 2 UISliders in sync? KVO? (I've never used KVO before).
Thanks
Assuming you already have an image for the track, and an image for the knots, you could compose a custom image on the fly (track plus appropriately positioned knots) and set it to your slider's track image. This would avoid the dual slider solution which seems a bit hacky.
The best thing that I can think of is creating see through buttons in the same way that you have done, but then making a custom slider track with the knots on it. So long as the knots are static, you can give the effect of having knots on the slider track, while using the system you already have in place.
精彩评论