Home > Blockchain >  How do you remove a navigation bar's large title bottom border before iOS 13?
How do you remove a navigation bar's large title bottom border before iOS 13?

Time:11-15

I want to hide/remove navigation bar large title bottom border in iOS 12. In newer versions it works fine.

func setupTransparentNavigationBar() {
    let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.colorWhite()]
    navigationController?.navigationBar.tintColor = UIColor.colorWhite()
    navigationController?.navigationBar.backgroundColor = UIColor.clear
    navigationController?.navigationBar.isTranslucent = true

    if #available(iOS 13, *) {
        let appearance = UINavigationBarAppearance()
        appearance.configureWithTransparentBackground()
        appearance.backgroundColor = .clear
        appearance.titleTextAttributes = textAttributes

        // Customizing our navigation bar
        navigationItem.standardAppearance = appearance
        navigationItem.scrollEdgeAppearance = appearance
    } else {
        navigationController?.navigationBar.titleTextAttributes = textAttributes
        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationController?.navigationBar.shadowImage = UIImage()
    }
}

Is there any way to remove this? Or is it native iOS behavior?

Screen shot for reference

CodePudding user response:

Try to you use this extension:

extension UINavigationController {
func hideHairline() {
    if let hairline = findHairlineImageViewUnder(navigationBar) {
        hairline.isHidden = true
    }
}
func restoreHairline() {
    if let hairline = findHairlineImageViewUnder(navigationBar) {
        hairline.isHidden = false
    }
}
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
 }
}

use it in viewWillAppear:

navigationController?.hideHairline()
  • Related