Image customization for UISegmentedControl for different states?

I have a UISegmentedControl in my XIB that has four segments. My designer and I decided to have certain images for the default state and other images for the selected state. Each segment will have different images for BOTH states. It seems that I can very easily set the image for each segment, but not for each state. How to adjust the image for both states for each segment (these are 8 images for 4 segments).

I was thinking of one method, but it does not use the UISegmentedControl itself. I could set the opacity of the control to 0, have the image with all the buttons in the default state behind it, and then have four different images on top of each segment. When the user selects a segment, the image corresponding to this segment will become visible, and all others will become hidden. It seems I just need to use this solution, but does anyone know an easy way using the standard UISegmentedControl to do what I need?

thanks

+6
source share
1 answer

Unfortunately, UISegmentedControl does not support this configuration on its own. But you can change segment images accordingly using the setImage:forSegmentAtIndex: method every time a user switches a control

+5
source

Source: https://habr.com/ru/post/923215/


All Articles