Reputation: 2127
I'm using an UINavigationController
with its default UINavigationBar
and I'm trying to turn the translucent effect off, so I can have a solid color on it. Apparently, it doesn't work with code but it is possible with storyboard with just one click (weird ?!!)
my code:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:APP_DELEGATE.map];
[navController setToolbarHidden:YES];
[navController.navigationBar setTranslucent:NO];
[navController.navigationBar setBarTintColor:[UIColor turquoiseColor]];
// [[UINavigationBar appearance] setBarTintColor:[UIColor turquoiseColor]]; | also doesn't work
Why doesn't it work ? How can I fix that ? Thanks.
Upvotes: 6
Views: 5825
Reputation: 416
UINavigationBar.appearance.barTintColor = [UIColor redColor];
UINavigationBar.appearance.tintColor = [UIColor whiteColor];
UINavigationBar.appearance.translucent = NO;
This will provides solid background color red and text color white with property as non-translucent.
Upvotes: 0
Reputation: 5667
This is the right way to do it. User appearance
proxy methods.
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[self.navigationController.navigationBar setTranslucent:NO];
Thats all & you are done. Use whatever colour you want. The above code makes the NavigationBar as opaque (i.e. Solid color).
Upvotes: 13
Reputation: 8210
And for all you Swiftians out there:
UINavigationBar.appearance().barStyle = UIBarStyle.Default
UINavigationBar.appearance().barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.translucent = false
The above should work for Swift 1.2 and Swift 2.
Upvotes: 4
Reputation: 2525
use this way for solid color of navigation bar i have faced this issue lots of time
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:APP_DELEGATE.map];
[navController setToolbarHidden:YES];
navController.navigationBar.barTintColor =[UIColor turquoiseColor];
[navController.navigationBar setTranslucent:NO];
Upvotes: 2
Reputation: 535988
What I ended up doing is making a UINavigationController subclass and overriding initWithRootViewController:
- and doing there exactly what you are doing (set translucent to NO and apply a bar tint color, except that now of course we are operating on self
).
Upvotes: 0