iOS10 去掉导航栏底部横线

2020-05-20  本文已影响0人  艾欧尼亚
   private var shadowImg = UIImageView()

   override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if #available(iOS 11, *) {
            navigationController?.navigationBar.shadowImage = UIImage()
        }else{
            if let subviews = self.navigationController?.navigationBar.subviews {
                for shadow in subviews  {
                    for sha in shadow.subviews {
                        if sha.isKind(of: UIImageView.self) && sha.bounds.size.height < 1 {
                            self.shadowImg = sha as! UIImageView
                        }
                    }
                }
                self.shadowImg.isHidden = true
            }
        }
    }
override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.searchView.textField.resignFirstResponder()
        if #available(iOS 11, *) {
            navigationController?.navigationBar.shadowImage = nil
            navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
        }else{
            self.shadowImg.isHidden = false
        }
        
    }
上一篇下一篇

猜你喜欢

热点阅读