简体   繁体   中英

Is there a way to change the height of a UINavigationBar in a UINavigationController Swift Xcode?

Is there a way to change (namely, decrease) the height of a UINavigationBar in a UINavigationController? I have tried the following to no avail:

extension UINavigationBar {

override open func sizeThatFits(_ size: CGSize) -> CGSize {
    return CGSize(width: UIScreen.main.bounds.size.width, height: 10)
    }

}

class CustomNavigationController : UINavigationController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        navigationBar.frame.size.height = 10
    }

}

Thanks in advance!

Try the below codes,

override func viewDidLayoutSubviews()
{
   super.viewDidLayoutSubviews()
   let height = CGFloat(72)
   navigationBar.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: height)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM