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?
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
Xcode 8
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.
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:
After:
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:
After:
This seems like a lengthy hack, but still better than going back and compiling using Xcode 8.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.
In iOS 11 we cannot change the navigation bar height, If you want to increase the height we should go with custom view.
Reference:
https://forums.developer.apple.com/thread/88202
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:
This answer did the job for me.
navigationController.navigationBar.setTitleVerticalPositionAdjustment(CGFloat(10),
forBarMetrics: UIBarMetrics.Default)
Related
I want to make my large title navigation bar to be back to the default nav bar like the image above, the image above is when I run the app on iOS 12, there is a separator line and the color is little bit grey.
but when I run the app in iOS 13 is like the image below, the navigation bar is completely white and it seems there is no dark grey separator
I want to make my nav bar in iOS 13 is exactly the same as iOS 12, which is little grey and it has separator line
and here is the code I run in viewWillAppear :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
}
I am using storyboard, and here is the setting I use. even from storyboard, as you can see, it seems the nav bar is already completely white and no separator
The behavior you are seeing is normal and correct in iOS 13. In iOS 13, a navigation bar with a large title is, by default, transparent. That means the white of the main view behind it shows through and it has no shadow (what you call the "separator"). You surely must have noticed this by now on your phone; iOS 13 has been around for almost a year! Apple's own apps generally look this way.
If that isn't what you want, configure the navigation bar's scrollEdgeAppearance to be what you do want.
There was an issue in iOS 11 for UINavigationBar, when set topItem.prompt with code:self.navigationController.navigationBar.topItem.prompt = #"(1/5)" :
it works well on iOS 8~10, when it shows the prompt navigationBar will automatically changed height from default 44 to 74 (iPhone 5S);
while in iOS 11 the navigationBar height was still 44, thought the appearance was fine, the navigation button can't be clicked due to this height issue. Please see the snap image on iOS 8 and iOS 11:
Is there any way to fix this issue without using custom navigationBar?
I've fixed this issue by adding code [self.navigationController.navigationBar sizeToFit]; after setting the topItem.prompt.
Seems that there was an issue in iOS 11 that navigationBar couldn't change its height dynamicly. If the topItem.prompt was set before navigationBar shown, it didn't have this issue. But after shown, if we want to add an topItem.prompt, have to add the code. letting the navigationBar change to right height.
I am having a very weird problem for iPad's multi-tasking resizing. This is how i set up my titleView:
navigationItem.titleView = theView
And I resize the SplitView in iPad multi-tasking so I can have two apps running side by side. After a few size changing, my titleview is missing from the UI.
Debugging it from the log, it is still in the navigationItem's titleview hierarchy but just not showing?
Any ideas?
I am having the exact same issue and have yet to find a resolution. When using the title property it works great, but using titleView the view will disappear at times when changing sizes when multitasking.
I found the following seems to have fixed my issue:
Assuming the view you want to place as the title view on the navigation item is declared as self.titleView:
[self.titleView.widthAnchor constraintEqualToConstant:44.0].active = true;
Hope that helps anyone else looking for the same thing.
I found this via this article:
Custom title view as large title in iOS 11 new navigation bar
I have a custom navigation bar that worked well until iOS 11. It appears smaller than it should and seems to ignore the status bar height or something.
I set the whole thing programmatically and the height is set to 64.
have you tried to disable (untick) safe area?
I'm updating an app from iOS 10 to iOS 11 with an iOS 9 target and this happens on every segue animation when a navigation bar is involved.
The animation starts with a small offset lower than the height it should be at and then moves to the proper height by the time the view has finished animating.
I'm not doing anything special to the navigation controllers, and it happens to each one in the app. If I programatically hide the navigation bar, the transitions animate normally.
Setting the tableView.contentInsetAdjustmentBehavior to .never in a UINavigationController fixes the problem.
Edit: Actually a better solution is to activate the Under Opaque Bars option for the TableViewController instead.
Otherwise the vertical scroll bars will be behind the iPhone X notch in landscape mode. This worked for me, because I use opaque bars. I don't know what happens if you use translucent bars.
The original solution is described by Prince on the Apple Developer Forums:
After some research ...I found that automaticallyAdjustsScrollViewInsets is deprecated in iOS 11, Now we are to use contentInsetAdjustmentBehavior in UIScrollView type views instead. Setting contentInsetAdjustmentBehavior to .never worked and also the 'UINavigationController translation slide up issue' wouldn't happen if the UINavigationBar is transulcent where the view is under the bar. (Thus the new way of doing the automaticallyAdjustsScrollViewInsets`)
This is not good for Storyboard users because this will have to be done in code.
The top/bottom layout guides were deprecated in iOS11 and I think your issue is connected to this. So you can change the constraints I think.
Read more here.