views:

440

answers:

2

Hi there I am using a segmented control in my app. I am also setting segmented controls setImage property to set an image for each segment of the control. I am not sure how to set an Image for its UIControlStateSelected state. I mean I would like to set an image for my segmented controls selected state. Please let me know how do I do that.

Thanks Sandy

A: 

Get the subviews from the segmented control until you find the correct one, and then set the image on the selected segment explicitly.

David Sowsy
If you do this, your app if very likely to crash on an OS update. It is also very likely to crash on the existing OS on iPhones with non-English regional settings (that happened to me for using a customized UISwitch)!
Dimitris
+1  A: 

Depending on what you want to acheive you can try the following:

  1. When you get a message from the control that a segment was clicked (UIControlEventValueChanged) change the image of the selected segment using the standard setImage:forSegmentAtIndex

OR

  1. Set the momentary property of the control to true - this was cause your buttons not to be selected.
  2. When you get the message that a segment was clicked replace it's image using the standard setImage:forSegmentAtIndex
Ron Srebro