删除导航栏的底部边框iOS7

Gna*_*amm 37 objective-c uinavigationbar ios7 xcode5

有没有办法删除iOS7自动显示在导航栏下方的底部边框?

wol*_*fan 48

这在带有半透明导航的iOS7上不起作用......

来自Apple文档的粘贴;

描述用于导航栏的阴影图像.默认值为nil,对应于默认阴影图像.当非零时,此属性表示要显示的自定义阴影图像,而不是默认值.要显示自定义阴影图像,还必须使用setBackgroundImage:forBarMetrics:方法设置自定义背景图像.如果使用默认背景图像,则无论此属性的值如何,都将使用默认阴影图像.

所以基本上你需要实现setBackgroundImage. 另外请注意,在iOS7上你将不再使用外观,但你将在viewController上下文中修改导航栏.

那是:

    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

在我的例子中,我把它放在viewDidLoad中(可以为UINavigationViewController中的每个UIViewController添加自定义行为).

  • 就我而言,这是有效的答案,而不是第一个.感谢您的代码和文档. (2认同)

muf*_*ffe 46

如果我理解你正确的尝试

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
Run Code Online (Sandbox Code Playgroud)

  • 可能值得注意的是(从iOS 7开始)为了使其工作,您还必须执行[[UINavigationBar外观] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]. (33认同)
  • 它在iOS 7上对我不起作用.我将导航栏的半透明属性设置为false.这可能是个问题吗? (4认同)

use*_*951 12

基于muffed2k回答+编程Thomas评论,这是我用来显示没有背景图像(ios5.1/6.0)和没有底部边框(ios7.0)的UINavigationBar:

  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6)
    {
        [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
        [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    }else
    {
        [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    }
Run Code Online (Sandbox Code Playgroud)


A F*_*kly 6

如果您正在使用Swift并遇到此问题,请在主ViewController中尝试:

override func viewDidLoad() {
    super.viewDidLoad()

    /// ...

    navigationController?.navigationBar.shadowImage = UIImage();
    navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)

    //...
}
Run Code Online (Sandbox Code Playgroud)

基于@ wolffan的上述答案