1

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
  • 128,072
  • 22
  • 173
  • 272

1 Answers1

2

Did you try adding the NavigationBar Delegate

@interface MyClass : UIViewController <UINavigationBarDelegate>

And the following method?

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

And remember to add a constraint of 20 from the top.

Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • Thank you thank you thank you! (Voted) Where did you find this in the docs? I've been hunting and hunting but couldn't find it. – Duncan C Dec 27 '13 at 20:25
  • 1
    BTW, it's better to pin your bar to the top layout guide than to fix it to 20 pixels down from the top. That way if you hide the status bar the navigation bar shifts up automatically. – Duncan C Dec 27 '13 at 20:28
  • I don't remember where I first found that, but according to the documentation, _Bars with this position draw their background extended upwards, allowing their background content to show through the status bar._ https://developer.apple.com/library/ios/documentation/uikit/reference/UIBarPositioning_Protocol/Reference/Reference.html – Guilherme Dec 27 '13 at 22:46