Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change navigationBar height in iOS 11?

Apparently changing the navigationBar height faced a new approach in iOS 11. in previous iOS versions it was possible to change the navigationBar height by hiding the default navigationBar and adding a new one with custom frame:

self.navigationController?.setNavigationBarHidden(true, animated: false) let customNavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 64)) self.view.addSubview(customNavigationBar) 

But it seems that it is not working in iOS 11 xCode beta. no matter what the new height is, it will always stay at 44.

this is what I've got in xCode 9:

enter image description here

does anyone know how to solve the problem?

like image 229
Mina Avatar asked Sep 10 '17 07:09

Mina


People also ask

What is navigation bar height iOS?

iPhone X added extra height for the Home Bar to toolbars and tab bars and their sizes are unchanged from iOS 11: 83 points tall in portrait and 53 points tall in landscape.

What is navigation bar height?

Personally I feel most comfortable using a navbar height of 64px. It is enough height to accommodate a logo, and there is room enough to use text in combination with symbols.


Video Answer


2 Answers

Your code is working fine and it´s nothing wrong with it. If you change the background color of your customNavigationBar you´ll see that you´ll get the navigation bar with the desired height. But it seems like it´s an issue with Xcode 9 to hide the default navigation bar.

Your code with:

Xcode 9 enter image description here

Xcode 8 enter image description here

As you can see in the Xcode 9 image, you have the custom navigation bar but the default one does not hide. Probably a bug in Xcode 9, I did not manage to hide it through the Storyboard either.

This seems to be a bug in Xcode 9, bug reports has been filed to Apple.

like image 188
Rashwan L Avatar answered Oct 10 '22 05:10

Rashwan L


This is more of a hack till Apple fixes the bug. I was facing the same issue, so I changed the top constraint of the navigation bar from 0 to 20.

Before: enter image description here

After: enter image description here

In case your UINavigationBar backgroundColor is something other than white, this will leave the status bar with a white color. You can fix this by adding the following in that particular UIViewController.

let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame) let statusBarColor = UIColor.red statusBarView.backgroundColor = statusBarColor view.addSubview(statusBarView) 

Before: enter image description here

After: enter image description here

This seems like a lengthy hack, but still better than going back and compiling using Xcode 8.3.

like image 30
Ameya Vichare Avatar answered Oct 10 '22 05:10

Ameya Vichare