I'm developing an iOS 6 and 7 app that requires the navigation bar to be taller than the usual 44/64 pts
I've searched high and low and so far it seems the cleanest solution is to use a category (or subclass) and implement the - (CGSize)sizeThatFits:(CGSize)size
method to return a different size.
This works fine in just making , however doing this causes all the items inside to rest at the bottom of the navigation bar, while I'd like to have them centered. I have tried using the Appearance Proxy protocol to define vertical offsets for the buttons, specifically this code
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment: -10 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundVerticalPositionAdjustment: -10 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment: -10 forBarMetrics: UIBarMetricsDefault];
Works just fine on iOS 6, producing this result
But doesn't work on iOS 7, giving me this instead.
I have read around that under iOS 7 the adjustments only work when using custom views but it seems odd to me, especially considering that setBackButtonTitlePositionAdjustment:forBarMetrics:
actually moves the text for the back button up, but not the chevron and that the title actually does nudge up.
I've also tried going for a subclassing route, using layoutSubviews to move down the views inside the UINavigationBar. This works, but of course when a new view controller is pushed the buttons jump around during the transition.
Am I missing something? Thanks in advance
UPDATE I have edited the description to make it clearer that my issue is with what's inside the bar, not the bar itself.
There is a quick crack to this, unless you find the proper solution, this would definitely work ;)
Check for system running iOS7.
Add Label to the Navigation Bar :
The cleanest solution I've found to this problem was to use my own subclass of
UINavigationBar
and center the buttons vertically by overriding thelayoutSubviews
method:To make a
UINavigationController
use your subclass ofUINavigationBar
you can use theinitWithNavigationBarClass:toolbarClass:
initialiser:Did you try to add the following code to your
viewDidLoad
Method :It is quickly explained in Apple migrating to iOS 7 Documentation : https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
//it's leave the status-bar height above.
You can change size of navigation bar with just changing it's frame:
Swift 3 version of Tiago his answer
Adjusting the titleView vertical postion