【问题标题】:Horizontal Separator NavBar IOS 7水平分隔符导航栏 IOS 7
【发布时间】:2013-10-15 13:16:40
【问题描述】:

我已经包含了对导航栏 (navigationController) 的需求,该导航栏的背景色调与栏 viewController 的背景相同......现在我遇到了一个问题......在导航栏和视图之间,我有一条将它们分开的水平线,从图片中可以看出..你能告诉我如何删除这条横黑线并使其更一致吗?

我在 AppDelegate 中试过这个:

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

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

但我没有得到结果。你能帮我吗?感谢所有 Rory。

【问题讨论】:

  • 请添加您提到的问题图片。
  • 可能是您使用的图像有黑色边框,请尝试将该边框颜色设置为透明。

标签: uiviewcontroller uinavigationcontroller ios7


【解决方案1】:

您还必须为导航栏设置背景图片才能达到您的要求

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

【讨论】:

  • 太好了,这让改变 AppDelegate 变得更加容易!非常感谢!
  • 它对我不起作用。我尝试在 Appdelegate 以及我的 viewController 中编写此代码。我没明白。为什么它不起作用。
  • @ErAmitSachdeva 我认为您还在导航栏上做一些其他技巧。否则它正在工作。
【解决方案2】:

您可以使用以下代码隐藏它:

UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
[overlayView setBackgroundColor:[UIColor whiteColor]];
[navBar addSubview:overlayView]; // navBar is your UINavigationBar instance
[overlayView release];

这里是参考:How to remove UINavigatonItem's border line

【讨论】:

  • Divya 完美运行......简而言之,您创建一个视图并调整导航栏,对吗?这一切在苹果的指导方针眼中都不应该是“负面的”吧?但是正确答案+1