美文网首页
iOS10 去掉导航栏底部横线

iOS10 去掉导航栏底部横线

作者: 艾欧尼亚 | 来源:发表于2020-05-20 11:27 被阅读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
            }
            
        }
    

    相关文章

      网友评论

          本文标题:iOS10 去掉导航栏底部横线

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