views:

4118

answers:

2

I'd like to change programmaticaly the tintColor of a UINavigationBar and keep the gradient as in Interface Builder.

When I change the tintColor in my code, the gradient disappears but when I change the tintColor in Interface Builder, the gradient is kept.

Any ideas?

+3  A: 

Set the barStyle to UIBarStyleBlackTranslucent Set the tintColor like this:

navigationBar.tintColor = [UIColor colorWithRed:.7 green:.5 blue:.2 alpha:1];

This will set the appropriate gradient. Use whatever combination you need.

Carlos Hernandez
Make that just navigationBar.tintColor = [UIColor colorWithRed: ..etc..]tintColor retains the color, so your code leaks.
Alfons
UIBarStyleBlackTranslucent has been deprecated. Better to use navigationBar.barStyle = UIBarStyleBlack; navigationBar.translucent = YES;
Amagrammer
A: 

I need to do the opposite - remove the gradient from UINavigationBar and make it's color solid. How do I do that? I've played with different styles but to no avail.

Thorny
I'm afraid there's no way to do that. Using a light color may looks like there is no gradient, but this is not a real solution...
pbernery
Override UINavigationBar drawRect function using categories and you'll be able to make its color solid. There is tutorial how to do that here: http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html
sniurkst