Reputation: 19
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.
Upvotes: 0
Views: 59
Reputation: 14397
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)
}
}
Upvotes: 1