I want to use a custom UINavigationBar
in one of my views, which is not a part of any UINavigationController
-hierarchy. When I drag a UINavigationBar
into Storyboard, it shows like this:
This bar is 44px, which would be enough if the status bar wouldn't share this space. Because iOS7 lets us use the entire screen, including the space for the status bar, the UINavigationBar
should be 64px tall, not 44px.
If I connect the view to a UINavigationController
's hierarchy, then it shows correct:
I read somewhere that if the UINavigationBar
has the property barPosition:
set to UIBarPositionTopAttached
, then the bar would be 64px. This is, however, a readonly
-property.
My search results have only shown something I consider a "work-around". By adding a useless UINavigationController
before this UIViewController
, I can pretend to have a hierarchy, and it will add the UINavigationBar
with 64px automatically.
Is there really no way to have a 'rogue'(without the help of a navigation controller) UINavigationBar
that covers 64px?
If that is the case, is there any valid reasons as to why?
(I'm not saying the UINavigationBar
should be 64px by default, but there should be an option for it in the inspector)
(I also see people answering with programmatic ways to solve this. Even though these answers works, I'd still have to design the storyboard with that in mind (a gap). What I want to know is if it's possible to set this in storyboard, or rather, why isn't it allowed?)
You can set the property barPosition
to UIBarPositionTopAttached
another way!
Implement -positionForBar:
in the delegate class:
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
Your navigation bar's top must also be anchored to the Top Layout Guide.