IOS 7 | The navigation bar / toolbar buttons are very close to the status bar

I have a problem when dragging a navigation bar or toolbar (storyboard) into the controller of my view.

UINavigationBar:

UINavigationBar

As you can see in the image above, the right button almost overlaps the status bar.

The same thing happens with UIToolbar:

Uitoolbar

These view controllers are intended to be used as Modal, so I do not use the UINavigationController.

In another section, I use the UINavigationController and it looks the way I expect:

UINavigationController

How to drag a UINavigationBar / UIToolbar to a view controller without overlapping the status bar?

+40
ios7 uistoryboard uinavigationbar uitoolbar
Sep 19 '13 at 17:55 on
source share
6 answers

Navigation panels or toolbars should be able to (0, viewController.topLayoutGuide.length ) with the positioning of the UIBarPositionTopAttached panel. You must set the delegate of your navigation bar or toolbar to your view controller and return UIBarPositionTopAttached . If positioned correctly, you will get the result in your third image.

More information here: https://developer.apple.com/documentation/uikit/uibarpositioningdelegate?language=objc

+48
Sep 19 '13 at 17:59 on
source share

Take the following steps

Drag the navigation bar into the ViewController in Xib, set the ViewController as your delegate. Note that the NavigationBar must be at (0, 20)

In ViewController compatible with UINavigationBarDelegate

 @interface ETPViewController () <UINavigationBarDelegate> 

Implement this method

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

positionForBar tells the navigation bar if it should increase its background up the status bar

+24
Nov 24 '13 at 8:26
source share

Please see my answer here, I copied the content below for convenience:

stack overflow

The easiest workaround I have found is to wrap the view controller that you want to present in the navigation controller and then present that navigation controller.

 MyViewController *vc = [MyViewController new]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; [self presentViewController:nav animated:YES completion:NULL]; 

Benefits:

  • No need to configure frames.
  • The same code works on iOS 6 and iOS 7.
  • Less ugly than other workarounds.

Disadvantages:

  • You probably want to leave your XIB empty in the navigation bars or toolbars and programmatically add UIBarButtonItems to the navigation bar. Fortunately, this is pretty easy.
+9
Sep 20 '13 at 8:50
source share

You can solve this problem using the automatic layout in accordance with this technical note (Preventing the display of the status bar from your views).

Here are a few excerpts:

Add a vertical space constraint to the topmost view

  • Control drag and drop from UIToolbar to Top Layout Guide
  • In the popover, select "Vertical Spacing"
  • Change the Vertical Spacing Constant constant to 0 (zero)

If you have other subitems below the UIToolbar, link these views to the toolbar instead of the top layout guide

This will support ios6 and ios7.

+5
Sep 27 '13 at 2:39 on
source share

You can also control it by increasing the height of the navigation bar, providing a 620x128 image for the ios version. And this image is used in:

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?YES:NO) { [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"newImage.png"] forBarMetrics:UIBarMetricsDefault]; }else{ [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"previousImage.png"] forBarMetrics:UIBarMetricsDefault]; } 
0
Sep 27 '13 at 12:35 on
source share

I gave up and had to set the navigator height limit to 64 in xCB based on VC. viewController.topLayoutGuide.length is 0 in viewDidLoad, despite the presence of the status bar: - [which means that in a non-universal application on the ipad you should have 20 pixels at the top (in the status bar separate from the iphone simulation window)

0
Mar 17 '16 at 16:31
source share



All Articles