我有一个应用程序,有时需要它的导航栏融入内容。

有人知道怎么去掉或者改变这个烦人的小条的颜色吗?

在下图中,我说的是根视图控制器下面1px的高度线


当前回答

这里有另一个选择-我认为这只适用于你不需要半透明的导航栏(我没有)。我只是在导航栏的底部添加了一个1像素高的UIView(在导航栏下面1像素),颜色与我的导航栏相同:

UIView *view = [[UIView alloc] init];
[view setBackgroundColor:self.navigationController.navigationBar.barTintColor];
[self.navigationController.navigationBar addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.height.equalTo(@(1.0f));
    make.leading.trailing.equalTo(self.navigationController.navigationBar);
    make.bottom.equalTo(self.navigationController.navigationBar).offset(1.0f);
}];

我正在使用砌体添加约束。

其他回答

在iOS8中,如果你设置UINavigationBar。你可以设置酒吧的背景为无边框的素色。

迅速:

UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().barStyle = UIBarStyle.Black
UINavigationBar.appearance().barTintColor = UIColor.redColor()
[tabviewController.view setBackgroundColor:[UIColor blackColor]];

对我来说[UIColor blackColor]可能是你的背景色, tabviewController是你的UITabBarController,如果你正在使用它!

编写自己的初始化式:D

import Foundation
import UIKit

extension UINavigationController {
    convenience init(rootViewController : UIViewController, hidesShadow : Bool) {
        self.init(rootViewController : rootViewController)
        self.navigationBar.setValue(hidesShadow, forKey: "hidesShadow")
        if hidesShadow {
            self.extendedLayoutIncludesOpaqueBars = true
            self.navigationBar.isTranslucent = false 
        }
    }
}

对于iOS 9用户,这对我来说很有效。只要加上这个:

UINavigationBar.appearance().shadowImage = UIImage()

在Swift 3中,我们就是这样做的

对于任何视图控制器:

navigationBar.shadowImage = UIImage()
setBackgroundImage(UIImage(), for: .default)

对于整个应用程序:

UINavigationBar.appearance().setBackgroundImage(UIImage(),barMetrics: .Default)
UINavigationBar.appearance().shadowImage = UIImage()