Search code examples
iosuikituislider

Multicolored UISlider, is it possible?


I often see UISlider's with a little yellow line through them, generally indicating an advertisement or something similar. I'm trying to replicate this functionality, and am wondering about the best way to approach this. Can you change specific x-cordinates on the UISlider to be a different color? I'd rather not add in subviews to sit on top of my slider but I've seen people do it...


Solution

  • You can do this without adding/managing your own subviews, but you will need custom images. You can use the setMinimumTrackImage:forState and setMaximumTrackImage:forState which are built in properties of the UISlider API. The minimum image will show from the minimum end of the slider to the thumb image, and the maximum image will show from the thumb image to the maximum end of the slider. So you could either make these the same, or different, depending on the effect you want to create.

    Customizing the slider's appearance Apple reference