navigation controller bar is being cut off

2019-04-29 18:03发布

问题:

If hiding the status bar by choosing status bar style = hide during application launch and I am customizing uinavigation bar like the following

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: @"navbar-iphone.png"]
                                       forBarMetrics:UIBarMetricsDefault];

and when I am getting this : the navigation bar is cut off the top.

and

Any ideas about this situation and how to fix it ?

回答1:

You can try this.

during application launch. here viewController is UINavigationController.

//set status bar hidden true.
    [[UIApplication sharedApplication]setStatusBarHidden:YES]; 

//You can set navigation bar frame to start from 0.0,0.0
    self.viewController.navigationBar.frame = CGRectOffset(self.viewController.navigationBar.frame, 0.0, -20.0);

//set the image u want.
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: @"navbar-iphone.png"]
                                       forBarMetrics:UIBarMetricsDefault];

Or

[[UIApplication sharedApplication]setStatusBarHidden:YES]; 
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: @"navbar-iphone.png"]
                                           forBarMetrics:UIBarMetricsDefault];
[self.viewController setWantsFullScreenLayout:YES];