0

In the latest version of xcode, I wrote the following code in the viewDidLoad to change the height of the NavigationBar.

self.navigationController?.navigationBar.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.size.width, height:40)

However, I couldn't change the height of the NavigationBar.

I would appreciate it if you could tell me how to solve it.

Tomonari
  • 19
  • 2
  • Does this answer your question? [How can I change height of Navigation Bar - Swift 3](https://stackoverflow.com/questions/40751366/how-can-i-change-height-of-navigation-bar-swift-3) – rbaldwin May 13 '20 at 08:32
  • please let me know if my answer solved your issue ? – Jawad Ali May 14 '20 at 13:19

1 Answers1

1

There are mainly 2 Approaches that i used

First Approach

Better to create Subclass of UINavigationController ... and add this method there .. Use this class as NavigationController

  class MyNavigationController: UINavigationController {

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

}

Second workaround

You can create a Subclass of UINavigationBar like this

class MyNavigationBar: UINavigationBar {

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

}
Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
  • Thank you!! The First Approach was able to build successfully. However, the second approach didn't work. – Tomonari May 16 '20 at 07:31