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.
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).
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.
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];
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