I am globally setting the appearance for all my UISegmentedControl’s. However I noticed that when I do this it breaks the disabled state.
Here is the code I have to change the titleTextAttributes
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor colorWithRed:0x49/255.0 green:0x49/255.0 blue:0x49/255.0 alpha:1], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
nil];
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
Now this works great and all segmented controllers are updated.
But the items that I had disabled with setEnabled:forSegmentAtIndex: aren’t disabled anymore and are clickable. Why does this happen? How can I get them to be disabled again. I tried to apply it to the disabled state as well but it doesn’t work.
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateDisabled];
Well it appears that setting a global appearance for the UISegmentedControl wasn’t the best approach as it does not honor the UIControlStateDisabled.
I thought I had to use UIControlStateDisabled since nothing was working, but it appears that setting the background directly works. So I just ended up making a UISegmentedControlExtended class that initializes the background and now the setEnabled function works fine.