iPhone App 开发

一种简单粗暴隐藏导航栏底部的黑(白)线方法

2019-02-25  本文已影响0人  一页清风

主要方法:

func findNavBarHarLineImageView(v: UIView) -> UIView? {
       if v.isKind(of: UIImageView.self) && v.bounds.size.height <= 1 {
           return v
       }
       for subview in v.subviews {
           if let img = findNavBarHarLineImageView(v: subview) {
               return img
           }
       }
       return nil
   }

1、定义一个视图:

var navBarHairlineImageView: UIView?

2、在控制器创建时指定这个视图

override func viewDidLoad() {
        super.viewDidLoad()
        navBarHairlineImageView = findNavBarHarLineImageView(v: (navigationController?.navigationBar)!)
    }

3、在viewWillAppear方法中隐藏:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navBarHairlineImageView?.isHidden = true
    }

4、在viewDidDisappear方法中恢复显示:

override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        navBarHairlineImageView?.isHidden = false
    }
上一篇 下一篇

猜你喜欢

热点阅读