Separator between navigation bar and view - iOS 7

主宰稳场 提交于 2019-12-01 16:06:17

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

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

Add this:

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

in your AppDelegate.m in the application didFinishLaunchingWithOptions method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!