简体   繁体   English

有没有办法在 UINavigationController Swift Xcode 中更改 UINavigationBar 的高度?

[英]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?有没有办法在 UINavigationController 中改变(即减少)UINavigationBar 的高度? 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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在不使用UINavigationController的情况下更改Storyboard中UINavigationBar的高度? - Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController? 更改UINavigationController时的UINavigationBar高度 - UINavigationBar height when changing UINavigationController 有没有办法在Swift 4中更改UINavigationBar的背景颜色 - Is there a way to change the background colour of a UINavigationBar in swift 4 更改UINavigationBar高度 - Change UINavigationBar Height 如何根据 UINavigationController 中显示的 UIViewController 更改 UINavigationBar - How to change UINavigationBar depending on the UIViewController shown in UINavigationController 以编程方式更改 UIImageView Xcode Swift 的高度和宽度 - Programmatically change the height and width of a UIImageView Xcode Swift UINavigationBar中的UISearchBar不能更改高度? - UISearchBar in UINavigationBar can not change height? UINavigationController工具栏高度在方向更改时 - UINavigationController toolbar height on orientation change 在UINavigationBar中快速更改UIBarButtonItem的位置 - Swift Change Position of UIBarButtonItem in UINavigationBar 使视图的高度随图像Xcode的高度动态变化 - Make the height of the view dynamically change with height of image Xcode swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM