views:

974

answers:

2

Hello,

How to change the color of the button in the UINavigationBar? For example, I use UINavigationBar with light gray background, and I need the buttons to be dark gray (almost black). It will be cool to have one solution for all button types, i.e. back button, button with image, button with text

thanks

+1  A: 

Similar question all ready posted here.

http://stackoverflow.com/questions/505180/how-to-change-the-text-color-on-uinavigationbar-button-items

Convolution
Thanks. I read it. But it's actually about how to change label color, but I need to change background color. I can get the UIButton object from the UINavigatorBar, but what the next step?
Dmitry
Sorry about that, I understand what you mean now.http://stackoverflow.com/questions/1340639/button-color-in-navigation-bar-iphoneThis might point you in the right direction, as well as the follow up comment here:http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/It looks like you will have to use an image for the button, or subclass existing UI elements. Changing the tint color property of the navigationbar changed both the bar and button color, not the individual elements.
Convolution
A: 

This is a terrible hack but, when placed in -viewDidAppear: method(s), it will change the background color (tint, actually) of UINavigationButtons.

UINavigationBar *navBar = [[self navigationController] navigationBar];
for (UIView *subview in [navBar subviews])
    {
    if ([NSStringFromClass([subview class]) isEqualToString:@"UINavigationButton"])
        {
        if (![[subview title] isEqualToString:@"Done"])
            [subview setTintColor:[UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0]];
        }
    }

It will not however change tint for UINavigationItemButtonViews - and this is what is used for the navigation back buttons. If someone finds a way to affect them, please let me know.

westsider