UISegmentedControl.enabled = NO does not reduce it

I have a UISegmentedControl in a UIView in my popover that I want to disable in some cases. A segmented control is configured using the Interface Builder in the nib file. Checked IB checkbook "Enabled".

To disable it, I wrote:

 self.segmentedControl.enabled = NO; // or YES when I want it enabled 

What works to such an extent that from there on a segmented control does not respond to touch events.

However, there is no graphical feedback. I would like the segmented control to be dim (gray) when it is disabled. I tried to set its highlighted property to NO , but with no effect.

This should be possible, since disabling the UISegmentedControl using Interface Builder causes the dimming effect that I want.

However, if I do this, my code will not be able to enable it again:

 self.segmentedControl.enabled = YES; 

won't turn it on: even if he starts to accept touch events again, he will remain dull.

As if IB "enabled" checkbox controls two properties: enabled and dimmed . But what is this dimmed property that I cannot find?

What did I miss?

This is in the 4.3 iPad simulator.

(note that I'm talking about the whole control, and not about its individual segments).

Edit:. I did a bit of research, and I found that disabling a segmented control in IB also sets its alpha property to 0.5.

When adding:

 self.segmentedControl.alpha = 0.5; // or 1.0 if enabled 

Now my application looks fine.

Am I right in thinking that setting the enabled property should also take care of the look of the screen?

+4
source share
2 answers

I found that this works for each segment:

 [self.segmentedControl setEnabled:NO forSegmentAtIndex:0]; 

The effect is subtle, but it is gray. To execute all segments:

 for(int index=0; index<self.segmentedControl.numberOfSegments; index++) { [self.segmentedControl setEnabled:NO forSegmentAtIndex:index]; } 
+6
source

I ran into the same problem with an interesting twist. The interface behaves the way you describe it on an iPad running iOS 4.3. However, segmented control works on iPads running iOS 5.0. So, my guess is that this is a bug that was fixed by Apple in iOS 5.

+3
source

All Articles