I've got a UINavigationController and i've changed it to white using the Tint property of the navigation bar in Interface Builder. But the text in buttons and the title is still the default color, white, and so gets lost against the white background. Anyone know how to work around this?
The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color. navbar-dark: This class will set the color of the text to light.
Use any of the . bg-color classes to add a background color to the navbar. Tip: Add a white text color to all links in the navbar with the . navbar-dark class, or use the .
for (id subView in theNavigationBar.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
[(UIButton *)subView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[(UIButton *)subView setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
}
}
As of iOS 5 this it much easier, using the UIBarButtonItem appearance proxy:
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor],
UITextAttributeTextColor,
[UIColor clearColor],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes: attributes
forState: UIControlStateNormal];
Set this in application:didFinishLaunchingWithOptions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With