Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position of navigation bar for modal view - iOS7

In a navigation controller, you automatically get the correct colour and position of a navigation bar as expected.

like this

enter image description here

But in modal view, when you drag in a navigation bar, you can position it right at the top, which is too close to the carrier / battery info.

enter image description here

So you can drag it down, guess how far so it matches the position of the automatically created one, but then you have a colour discrepancy. I have tried changing status bar settings in IB, doesnt make a difference.

enter image description here

Is there a correct way to do overcome this, as in make a modal view look like the auto generated nav view.

Thanks

like image 792
DogCoffee Avatar asked Sep 11 '13 09:09

DogCoffee


People also ask

Can you change iPhone navigation bar?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.

What is navigation bar height iOS?

iPhone X added extra height for the Home Bar to toolbars and tab bars and their sizes are unchanged from iOS 11: 83 points tall in portrait and 53 points tall in landscape.


1 Answers

The best way to overcome this in iOS 7 is by conforming to the new UIBarPositioningDelegate protocol.

You connect the delegate of your NavigationBar to your view controller (set your view controller as the delegate for the navigation bar either through storyboard or through code) and conform to that protocol and by implementing the method

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

You can remove the top gap in the view controller. You need to place the bar 20 points below the top edge

like image 146
Matt Avatar answered Sep 23 '22 04:09

Matt