Search code examples
iosswiftuikituislider

UISlider - Add UILabel to min/max UIImageView?


As shown below, UISlider has a Minimum Image and Maximum Image.

These imageView elements can be set to any UIImage.

I have a custom UISlider scenario and I'm trying to simply make the left and right image a string (UILabel).

Any smart ideas about how I might inject a UILabel into these elements? Or failing that, how I can extend my UISlider subclass so that it has a UILabel either side of it?

I guess I could encapsulate inside another UIView but I don't love that idea.

Thanks

WS

UISlider layout


Solution

  • Here is smart & simple idea to achieve, that you want.

    Look at this snapshot:

    • Do not set min and max image for UISlider.
    • Set UILabels on left and right of UISlider. UILabels allows to set string value.
    • You can create custom view or IBDesignable with slider & two labels. This would be very easier than subclass UISlider and overriding of default properties.

    enter image description here