i\'ve been trying to remove the navigationBars border without luck. I\'ve researched and people seem to tell to set shadowImage and BackgroundImage to nil, but this does not
Only this worked for me,
self.navigationController?.navigationBar.shadowImage = UIImage()
Ref
Set barStyle
to .Black
before setting the tint:
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barStyle = .Black
self.navigationController?.navigationBar.barTintColor = UIColor.blueColor()
Swiftier method of Jack Chen:
extension UINavigationController {
var isHiddenHairline: Bool {
get {
guard let hairline = findHairlineImageViewUnder(navigationBar) else { return true }
return hairline.isHidden
}
set {
if let hairline = findHairlineImageViewUnder(navigationBar) {
hairline.isHidden = newValue
}
}
}
private func findHairlineImageViewUnder(_ view: UIView) -> UIImageView? {
if view is UIImageView && view.bounds.size.height <= 1.0 {
return view as? UIImageView
}
for subview in view.subviews {
if let imageView = self.findHairlineImageViewUnder(subview) {
return imageView
}
}
return nil
}
}
Using:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isHiddenHairline = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.isHiddenHairline = false
}
for the swift3 you should write slightly different way:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(),
for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
The border line is an UIImageView and removing a subview which is an imageView will remove barButtonItems with UIImageView. Below code will help you remove it. Hope this helps someone who faced an issue like me.
for parent in self.navigationController!.navigationBar.subviews {
for childView in parent.subviews {
if childView.frame.height == 0.5 {
childView.removeFromSuperview()
}
}
}
The border UIImageView is only 0.5 in height so this code removes only that.
Updated for Swift 4 in case someone is wondering
navigationBar.shadowImage = UIImage()
navigationBar.backIndicatorImage = UIImage()
It's even less verbose now.