在iOS 7中,导航栏和视图之间有一个灰色分隔符。
回到iOS 6,没有那条水平线,因此视图会与导航栏融为一体,就好像它们是相同的图像一样。现在我不知道如何删除它......
我已经尝试调整视图/导航栏的大小,但它没有帮助。有什么想法吗?
答案 0 :(得分:28)
其他答案对我不起作用。要删除分隔符,我必须设置背景图像和阴影图像,如下所示:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
答案 1 :(得分:20)
添加:
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
应用程序中的AppDelegate.m中的didFinishLaunchingWithOptions方法
答案 2 :(得分:5)
尝试
self.navigationController.navigationBar.translucent = NO;
在viewDidLoad
方法中,让我知道:)
如果您需要在每个ViewController上使用此效果,您可以执行以下操作:
[[UINavigationBar appearance] setTranslucent:NO]
或者您需要在首次实例化导航控制器时执行此操作。例如,如果导航控制器是应用程序的根视图控制器,则只需执行
即可UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
nav.navigationBar.translucent = NO;
中的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
另一方面,如果您通过segue实例化它(可以在适当的视图控制器中)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"navController"]){
UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
nav.navigationBar.translucent = NO;
}
}
依此类推(如果您实际上是从代码中实例化它,它应该是最简单的选项)。