iOS 10 custom navigation bar height

后端 未结 2 1599
遥遥无期
遥遥无期 2020-12-19 04:15

I implemented custom navigation bar height, by subclassing it with following code

class TMNavigationBar: UINavigationBar {

    ///The height you want your n         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-19 04:42

    I checked Interface debugger and this is what i see (so basically it's trying to change navigation bar height, bit it's stays same and it's showing just black space - which is window color):

    With later investigation i noticed that it's not calling: "_UINavigationBarBackground"

    Then i checked view.classForCoder from fast enumeration, and discovered that key is changed to "_UIBarBackground", so i updated layoutSubviews():

    override func layoutSubviews() {
        super.layoutSubviews()
    
        let shift = TMNavigationBar.heightIncrease/2
    
        ///Move the background down for [shift] point
        let classNamesToReposition = isIOS10 ? ["_UIBarBackground"] : ["_UINavigationBarBackground"]
    
        for view: UIView in self.subviews {
    
            if classNamesToReposition.contains(NSStringFromClass(view.classForCoder)) {
                let bounds: CGRect = self.bounds
                var frame: CGRect = view.frame
                frame.origin.y = bounds.origin.y + shift - 20.0
                frame.size.height = bounds.size.height + 20.0
                view.frame = frame
            }
        }
    }
    

    Cheers.

提交回复
热议问题