How to customize UISegmentedControl font color and UIToolbar gradient?
It seems Apple's UIToolbar
and some of the controls you can place on it, such as UISegmentedControl
, allow very limited customization. For exam开发者_运维知识库ple, we want our toolbar to looks something like this mock:
However, UIToolbar
only has a single tintColor
and 3 built-in barStyle
values that you can apply to it, so we can't get the gradient we're after. Is there some way to set the background image like many of the other controls?
Even worse, the UISegmentedControl
doesn't let you specify font or font color. It seems to enforce white 11pt Helvetica with a drop shadow, and the white is almost unreadable with the light tintColor
we're using.
I'd hate to rewrite UISegmentedControl
just to change the text color. But the only solution I've seen is very hacky -- it digs into the subviews of the subviews and changes properties on those -- seems likely to stop working whenever Apple feels like changing or disallowing it.
Is Apple really against us changing the text color on our segmented controls, or is there something I'm missing here?
Update: Apple finally added functions for customizing appearance in iOS 5. See jfortmann's answer.
You want to use the setBackgroundImage:forState:barMetrics: methods (probably on your appearance proxy) to set the background image. The text can be modified with setTitleTextAttributes:forState:. And finally, you'll need to change the divider for the possible states with setDividerImage:...
The docs are very informative as to how the images have to look.
精彩评论