Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color on UINavigationBar button items

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?

like image 584
lawrence Avatar asked Feb 02 '09 22:02

lawrence


People also ask

How do I change the color of my navigation bar text?

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.

How do I add color to my navigation bar in HTML?

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 .


2 Answers

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];
    }

}
like image 30
Taras Kalapun Avatar answered Oct 17 '22 23:10

Taras Kalapun


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:

like image 55
Michael Avatar answered Oct 17 '22 23:10

Michael