After upgrading to Xcode 9 and building my app for iOS 11, I have had a problem with the positioning of items in the UITabBar. They are offset to the left (shown in red outline).
I am using just a regular UITabBarController and have not done any custom UI code. I've tried looking for any new UITabBar properties that would effect this, but I can't find anything. Messing with UITabBar itemPositioning property doesn't fix the issue.
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?
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)
I want to make a navigation bar that changes height in it's detail view just like the messages app in iOS 10. How can I do that?
Edit:
I am looking to change the height dynamically. SizeThatFits() Permanently changes the height.
If you are trying to do something else that requires the navigation bar to be resized, that's not supported. iOS 11 and Above
Community bug reports
I'm supporting both iOS 7 and iOS 8 in my app and using storyboard with autolayout to setup my views. I'm having an issue with iOS 7 only.
I have a subview which has a constraint that sets its top space to the bottom of the top layout guide. This makes sure that the subview does not go underneath the translucent navigation bar at the top. It works fine on iOS 8, however on iOS 7 the subview goes underneath the navigation bar right below the status bar.
Any advice on how I can make this work on iOS 7 as well?
Currently I'm using a hack to get this to work on iOS 7, which is below:
override func viewDidLayoutSubviews() {
if NSProcessInfo.instancesRespondToSelector(Selector("isOperatingSystemAtLeastVersion:")) {
// iOS 7 navBar hack
} else {
let navBarHeight = self.navigationController?.navigationBar.intrinsicContentSize().height
self.navHeightConstraint.constant = navBarHeight!
self.view.layoutSubviews()
}
}
Basically I connected the constraint through Interface Builder and I adjust it's constant to the height of the navigation bar if it's iOS 7. If anyone has a better way, please let me know.