Swift 3移除导航栏下方的行

Tom*_*y K 1 uinavigationbar swift swift3

当我的项目在Swift 2中时,我可以使用以下代码:

extension UINavigationController {
func hairLine(hide: Bool) {
    //hides hairline at the bottom of the navigationbar

    for subview in self.navigationBar.subviews {
        if subview.isKind(of: UIImageView.self) {
            for hairline in subview.subviews {
                if hairline.isKind(of: UIImageView.self) && hairline.bounds.height <= 1.0 {
                    hairline.isHidden = hide
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

但是现在有些改变了,它不起作用了。不知道是因为Swift 3还是iOS10,还是我现在正在测试7plus和6s,但是它不再起作用。我会在其中调用正在显示的视图控制器的viewWillAppear。我在这里看到一个答案说要使用

    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
Run Code Online (Sandbox Code Playgroud)

但这没有用。我尝试用这两行替换旧的hairLine()的内容,尝试将它们直接放在viewWillAppear和viewDidAppear中,但仍然对我不起作用。

小智 5

尝试这个

self.navigationController?.navigationBar.setValue(true, forKey: "hidesShadow")
Run Code Online (Sandbox Code Playgroud)