Search code examples
iosswiftuinavigationbarswift5

Increase height of UINavigationBar in Swift 5


I'm trying to change the height of UINavigationBar but without success, in particular I have to show three buttons with font size 50, and actually this is the result:

enter image description here

As you can see, the first button it's been cut by navigation bar height, and it will be the same for the other ones. I've tried to add a subview inside the navigation bar but it still not working (text go outside the bar and the bar doesn't resize). Have you goto any advice or solution for this problem? I have seen that it's deprecated the possibility to change directly the height of the bar, but have you got some hacks?


Solution

  • What you can do is to subclass UINavigationBar and use that

    class HeightedNavigationBar: UINavigationBar {
    
        override func sizeThatFits(_ size: CGSize) -> CGSize {
            return CGSize(width: UIScreen.main.bounds.width, height: 104)
        }
    
    }