Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting images for UISegmentedControl for different states?

I have a UISegmentedControl in my XIB that has four segments. My designer and myself have decided to have certain images for 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 do I set the image for both states for every segment (which is 8 images for 4 segments).

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

Thanks

like image 221
Redneys Avatar asked Aug 19 '12 03:08

Redneys


1 Answers

Unfortunately UISegmentedControl does not support such setup by itself. But you may change the segment images appropriately with the help of setImage:forSegmentAtIndex: method by yourself each time the user toggles the control

like image 147
voromax Avatar answered Sep 29 '22 07:09

voromax