美文网首页
去掉导航栏黑线(Swift版本)

去掉导航栏黑线(Swift版本)

作者: 默默学习 | 来源:发表于2018-04-24 11:14 被阅读15次

    亲测,项目中正在使用

    override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            if self.navigationController != nil {
                let navBarHairlineImageView = self.findHairlineImageViewUnder(sView: self.navigationController!.navigationBar)
                navBarHairlineImageView.isHidden = true
            }
        }
        
        override func viewWillDisappear(_ animated: Bool) {
            super.viewWillDisappear(animated)
            
            if self.navigationController != nil {
                let navBarHairlineImageView = self.findHairlineImageViewUnder(sView: self.navigationController!.navigationBar)
                navBarHairlineImageView.isHidden = false
            }
            
        }
        
        
        func findHairlineImageViewUnder(sView: UIView) ->UIImageView {
            if sView.isKind(of: UIImageView.self) && sView.bounds.height <= 1 {
                return sView as! UIImageView
            }
            for sview in sView.subviews {
                let imgs = self.findHairlineImageViewUnder(sView: sview)
                if imgs.isKind(of: UIImageView.self) && imgs.bounds.height <= 1 {
                    return imgs
                }
            }
            return UIImageView.init()
        }
    

    相关文章

      网友评论

          本文标题:去掉导航栏黑线(Swift版本)

          本文链接:https://www.haomeiwen.com/subject/adgdlftx.html