How to change navigationBar height in iOS 11?
Solution 1
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.
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.
Solution 2
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.
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)
This seems like a lengthy hack, but still better than going back and compiling using Xcode 8.3.
Solution 3
The only way I could make it work was to delete the current custom Navigation Bar, and apply an embed UINavigationController to the UIViewController. Editor -> Embed In -> Navigation Controller.
On the new created Navigation Controller properties, on the Utilities (right side bar) menu 'Simulated Metrics' the 'Top Bar' attribute must be specified. In my case I needed the value: 'Opaque Navigation Bar'.
I also set the same value of 'Top Bar' on my UIViewController, just to make sure.
By doing that, a new 'Navigation Item' will be at your disposal, and you can re-add your Bar Button Items.
It's the best I could do while we wait for the Xcode 9 update to fix it.
Solution 4
Still haven't found how to change it size in pixels. But this is possible to create double navigation bar size (XCode 10.1):
self.navigationController?.navigationBar.prefersLargeTitles = true
Result:
Solution 5
In iOS 11 we cannot change the navigation bar height, If you want to increase the height we should go with custom view.
Related videos on Youtube
![Mina](https://i.stack.imgur.com/dwegR.jpg?s=256&g=1)
Mina
I'm interested in Swift programming. I have a lot of ideas in my head. I like to learn new things and discover as much as possible. I believe that there is no limitation in this world and everything is right infront of us, we just have to decide to see.
Updated on June 16, 2022Comments
-
Mina about 2 years
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:
does anyone know how to solve the problem?
-
Mina almost 7 yearsyes, i see the problem only in xCode 9 for iOS11. it also hides the default navigation bar and adds the custom on, but the problem is the height don't change to the new one.
-
Rashwan L almost 7 years@Mina, it does. The custom navigation bar is the green area you see in the Xcode 9 image.
-
Mina almost 7 yearsI've updated my question with an image. I've also added ``` customNavigationBar.backgroundColor = .red self.navigationController?.navigationBar.barTintColor = .purple self.navigationController?.navigationBar.barTintColor = .yellow``` but as you can see the navigation bar color didn't changed to purple or yellow, so I think it hides the default navigation bar. as you can see the title is added to the custom one not to the default one
-
Mina almost 7 yearsNow I'm confused, because you are right about that it draw the new navigation bar, but why the title is up there? (I doubt about not hiding the default navigation bar)
-
Rashwan L almost 7 years@Mina, as I said there is some bug. I could not either change the color of the default navigation bar. Your custom navigation bar is the red one and it´s drawn as you can see. Try to file a bug to Apple regarding this.
-
Mina almost 7 yearsThanks for your help, at least I know it draw the custom one.
-
Sulthan almost 7 yearsIncidentally you can also give a custom
UINavigationBar
class to yourUINavigationController
initializer which is easier than hiding a bar and showing a different one. -
Mina almost 7 yearsIt's an xCode 9 bug. because I've created ipa with xCode 8.3 and installed it on iOS 11 and everything is ok. but there is a problem with xCode 9 compiler. if i create spa with xCode 9 the problem shows up.
-
Faisal almost 7 yearsIt's really a Xcode 9 bug then. The navigation bar appears as intended in Xcode 8.3
-
Rashwan L almost 7 years@Faisal, indeed.
-
Faisal almost 7 yearsI have filed a bug about the issue.
-
hla almost 7 yearsSo technically the only solution is to wait for a patch on xcode 9 ? What happened if there is no correction ?
-
Rashwan L almost 7 years@hla, there will probably be some. I’ll see if I can come up with some workaround too.
-
Mina almost 7 yearsI've reported the issue too. the bug has still remained in xCode Golden master version.
-
Nevin Jethmalani almost 7 yearsDo you know that this is an issue for sure? Does anybody know a workaround that will allow us to use a navigation bar when we present a view modally?
-
SoftDesigner almost 7 yearsThe
Simulated Metrics
work only in the IDE not in the built app, don't they? -
Marco Nascimento almost 7 yearsExactly, just to have an idea of what will be displaying.
-
Rashwan L almost 7 years@NevinJethmalani, I have not found any solution yet. This should hopefully be fixed soon.
-
Nayan over 6 yearsYes. I also have the same issue. My app works fine when run it using xcode 8 but using xcode 9 it shows the gap under navigation bar. Seems like a bug.
-
Mina over 6 yearsIt increases the possibility of being rejected by apple.
-
Ameya Vichare over 6 yearsApple will only reject apps that make use of private APIs which are not recommended for public usage. Having said that, you could adopt this style until Apple fixes the issue.
-
D. Greg over 6 yearsThis is a solid solution until Apple decides to fix the bug. Thanks for posting!
-
Suresh Durishetti over 6 years@All, please share reported bug link for my reference.
-
Sean Lintern over 5 yearsAny chance you could add the code for updating the top constraint of the navigation bar please? Thanks.