Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Duncan C

macrumors 6502a
Original poster
Jan 21, 2008
853
0
Northern Virginia
In an app I'm developing (Xcode 5, >=iOS 7 auto-layout), I push a modal view controller. I want the modal view controller to have a navigation bar, so I add one, and add a constraint that positions it with it's top aligned with the top layout guide, so it is placed just under the status bar.
(I'm using my own navigation bar because I want to take advantage of the system's management of the edit button and add button nav bar items. )
The standard navigation bar has a very subtle light gray tint to it.
With navigation controllers, the system somehow tints the status bar, or extends the navigation bar up so that it colors the status bar the same color as the navigation bar, and the effect is as if the status bar is part of a taller navigation bar.
I don't know how to get this effect with a navigation bar I add to a window that is not managed by a navigation controller. I have vague memories of there being some sort of property I need to set that tells the status bar to adopt the tint color of the navigation bar, but despite searching and searching, I can't find it. I could put a view under the status bar and fiddle with it until it's color matches that of the navigation bar, but that's a hack, and if in the future the look of standard navigation bars changes, this approach would stop looking right.
Does anybody know the secret of this?
 

Duncan C

macrumors 6502a
Original poster
Jan 21, 2008
853
0
Northern Virginia

Thanks for the reply but I still don't get it. My app does not have a custom tint color, and I don't want a custom tint color.

I am adding a stock navigation bar to a modal window. I want the status bar to assume the color of the navigation bar, just like navigation bars that are managed by a navigation controller do.
 

Ubuntu

macrumors 68020
Jul 3, 2005
2,140
474
UK/US
Thanks for the reply but I still don't get it. My app does not have a custom tint color, and I don't want a custom tint color.

I am adding a stock navigation bar to a modal window. I want the status bar to assume the color of the navigation bar, just like navigation bars that are managed by a navigation controller do.

What happens if you remove the top layout guide reference? My understanding is that the status bar is transparent, so naturally the view controller's content will start below it unless you use toplayoutguide or modify the VC's edgesForExtendedLayout property.

Hope this helps.
 

Duncan C

macrumors 6502a
Original poster
Jan 21, 2008
853
0
Northern Virginia
What happens if you remove the top layout guide reference? My understanding is that the status bar is transparent, so naturally the view controller's content will start below it unless you use toplayoutguide or modify the VC's edgesForExtendedLayout property.

Hope this helps.

That doesn't work either. If you do that the navigation bar gets placed under the transparent status bar, and they overlap with each other.

What I want is the way a navigation bar draws in a navigation controller, where the status bar takes on the color of the navbar.
 

Duncan C

macrumors 6502a
Original poster
Jan 21, 2008
853
0
Northern Virginia
Ok, I just got the answer from Stack Overflow (link)

You have to set up your view controller to conform to the UINavigationBarDelegate protocol:

Code:
@interface MyClass : UIViewController <UINavigationBarDelegate>
Then make your view controller the navigation bar's delegate (can be done by control-dragging from the navigation bar to "files' owner" in IB)

Finally, you need to add this method:

Code:
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar 
{
    return UIBarPositionTopAttached;
}


In an app I'm developing (Xcode 5, >=iOS 7 auto-layout), I push a modal view controller. I want the modal view controller to have a navigation bar, so I add one, and add a constraint that positions it with it's top aligned with the top layout guide, so it is placed just under the status bar.
(I'm using my own navigation bar because I want to take advantage of the system's management of the edit button and add button nav bar items. )
The standard navigation bar has a very subtle light gray tint to it.
With navigation controllers, the system somehow tints the status bar, or extends the navigation bar up so that it colors the status bar the same color as the navigation bar, and the effect is as if the status bar is part of a taller navigation bar.
I don't know how to get this effect with a navigation bar I add to a window that is not managed by a navigation controller. I have vague memories of there being some sort of property I need to set that tells the status bar to adopt the tint color of the navigation bar, but despite searching and searching, I can't find it. I could put a view under the status bar and fiddle with it until it's color matches that of the navigation bar, but that's a hack, and if in the future the look of standard navigation bars changes, this approach would stop looking right.
Does anybody know the secret of this?
 

Ubuntu

macrumors 68020
Jul 3, 2005
2,140
474
UK/US
Ah, I see. Sorry my post wasn't useful, and thanks for updating us with the answer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.