方法一
方法摘自http://blog.it985.com/9808.html
代码已改写为swift
class demo: UIViewController {
fileprivate var navBarHairlineImageView: UIImageView?
override func viewDidLoad() {
// 找到导航条底部横线的view
navBarHairlineImageView = self.findHairlineImageViewUnder(view: (self.navigationController?.navigationBar)!)
}
override func viewWillAppear(_ animated: Bool) {
// 隐藏
self.navBarHairlineImageView?.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
// 显示
self.navBarHairlineImageView?.isHidden = false
}
/// 寻找导航条底部横线
func findHairlineImageViewUnder(view: UIView) -> UIImageView? {
if view.isKind(of: UIImageView.classForCoder()) && view.bounds.size.height <= 1 {
return view as? UIImageView
}
for subView in view.subviews {
let imageView = self.findHairlineImageViewUnder(view: subView)
if imageView != nil {
return imageView
}
}
return nil
}
}
方法二
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];