Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an opaque UINavigationBar on iOS 7

Is there any way to make the UINavigationBar, targeted for iOS 7, a solid color with no translucency? I have tried setting the backgroundColor, the barTintColor, opaque, transparent/translucent, etc... and nothing works.

Anyone know how to do this?

Here are some chunks of code I have been using. Notice the properties I have set on the navigationBar. None of them, in any order or combination have worked.

@property (strong, nonatomic) UITabBarController *tabBarController;  testViewController = [[TestViewController alloc] init]; anotherViewController = [[AnotherViewController alloc] init]; navigationController = [[UINavigationController alloc]                             initWithRootViewController:testViewController];  navigationController.navigationBar.barTintColor = [UIColor darkGrayColor; navigationController.navigationBar.barStyle = UIBarStyleBlack; navigationController.navigationBar.translucent = YES; navigationController.navigationBar.opaque = YES;  NSArray *tabBarViewControllers = [NSArray arrayWithObjects:                                       navigationController,                                       anotherViewController, nil]; self.tabBarController.viewControllers = tabBarViewControllers; 
like image 682
tentmaking Avatar asked Oct 04 '13 02:10

tentmaking


People also ask

How do I make my navigation controller transparent?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .

How do I use the navigation bar in Xcode?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.


2 Answers

Your code lists navigationController.navigationBar.translucent = YES;

Set it to NO.

like image 153
Vadoff Avatar answered Sep 22 '22 19:09

Vadoff


To make it totally opaque u can just change the style of the navigation bar from the property section itself!

Just set the style as Black!

This is how it looks like when u make it black

like image 40
marmikshah Avatar answered Sep 24 '22 19:09

marmikshah