How to remove border of the navigationBar in swift?

前端 未结 25 2074
执笔经年
执笔经年 2020-12-02 04:41

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

25条回答
  •  感情败类
    2020-12-02 05:35

    Swift 5

    When using setBackgroundImage / shadowImage to hide the hairline, there's a slight delay. This method removes the delay. Credit to Chameleon Framework. This is the method they use (in ObjC)

    
    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
        }
    }
    
    

提交回复
热议问题