Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl does not respect divider images set for UIControlStateDisabled

I'm using the new UIAppearance API in iOS 5 to style a UISegmentedControl with custom graphics. I need to be able to set some segments to be disabled at times during execution, but the UIAppearance methods don't seem to allow me to set a divider image for the UIControlStateDisabled state.

I'm calling:

[[UISegmentedControl appearance] setDividerImage:disabledSelectedImage
                                    forLeftSegmentState:UIControlStateDisabled
                                    rightSegmentState:UIControlStateSelected
                                    barMetrics:UIBarMetricsDefault];

where disabledSelectedImage is a resizable image from this resource:

disabled-selected-image

Yet when I set the left segment to be disabled ([UISegmentedControl setEnabled:forSegmentAtIndex:]), the result is this:

UISegmentedControl UI glitch

You can clearly see that the UISegmentedControl has defaulted to use the UIControlStateNormal-UIControlStateNormal divider image.

It seems perfectly happy for me to set a background image using UIControlStateDisabled

[[UISegmentedControl appearance] setBackgroundImage:disabledImage
                                    forState:UIControlStateDisabled
                                    barMetrics:UIBarMetricsDefault];

(and respects the image I supply while in the disabled state) but not a divider image. Has anyone come across this or found a solution?

like image 731
Ell Neal Avatar asked Oct 08 '22 10:10

Ell Neal


1 Answers

I've decided that this must be an iOS bug and have filed a radar with Apple. My solution to the problem for now is to remove segments, rather than disabling them.

like image 138
Ell Neal Avatar answered Oct 10 '22 23:10

Ell Neal