问题
I'm wondering if I can change the background color of just the prompt of the UINavigationBar (e.g. to red, while the rest of the navigation bar stays black), so I can use the prompt property of the UINavigationItem to display status / error messages as a one-liner.
回答1:
Nope. But you can set the prompt to an empty string, and place a red-colored label on top of it.
回答2:
This is an old question, but since the introduction of appearance
there is a much easier way to setting prompt color (and other properties) than adding a subview.
in didFinishLaunchingWithOptions
put
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor theColorYouWantYourPromptToBe], UITextAttributeTextColor, otherVariables, nil]];
来源:https://stackoverflow.com/questions/2027573/iphone-possible-to-change-the-color-of-just-the-prompt-of-the-uinavigationbar