Lord Zsolt
Lord Zsolt

Reputation: 6557

Separator between navigation bar and view - iOS 7

In iOS 7 there's a grey separator between the navigation bar and the view.

Back in iOS 6, there wasn't that horizontal line, thus the view would blend in with the navigation bar as if they were the same image. Now I don't know how to remove it...

I've tried resizing the view / navigation bar, but it doesn't help. Any ideas?

Upvotes: 12

Views: 14985

Answers (3)

James Harpe
James Harpe

Reputation: 4345

The other answers did not work for me. To remove the separator, I had to set the background image AND the shadow image, like so:

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

Upvotes: 28

micantox
micantox

Reputation: 5616

Try with

self.navigationController.navigationBar.translucent = NO;

In your viewDidLoad method and let me know :)

If you need this effect on every ViewController, you could simply do:

[[UINavigationBar appearance] setTranslucent:NO]

Or you'll need to do this where you first instantiate the navigation controller. For example, if the navigation controller is the root view controller of your app you can simply do

UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
nav.navigationBar.translucent = NO;

in your

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

If, on the other end, you instantiate it through a segue you could do (in the appropriate view controller)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if([segue.identifier isEqualToString:@"navController"]){     
       UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
       nav.navigationBar.translucent = NO;
   }
}

And so on (if you're actually instantiating it from code, it should be the easiest option).

Upvotes: 5

martin
martin

Reputation: 1007

Add this:

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

in your AppDelegate.m in the application didFinishLaunchingWithOptions method

Upvotes: 20

Related Questions