3

Any ViewController added to the NavigationController directly has a gray status bar which matches the color of the NavigationBar.

But Whenever I display a Modal, the status bar is white, which doesn't match the NavigationBar I have placed in there?

I have seen tons of answers on here, most of them don't work, and the ones that do don't seem to be good solutions. For instance I don't want to wrap every single modal inside of a UINavigationController.

I tried the following which was also recommended which completely gets rid of my status bar, and that's not what I want.

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
} 

So what's the magical solution here?

aryaxt
  • 76,198
  • 92
  • 293
  • 442
  • Is there simply not a solution to this? It's been a while since you asked, and no accepted answer? – elsurudo Jun 01 '15 at 19:15
  • @elsurudo "For instance I don't want to wrap every single modal inside of a UINavigationController" I actually ended up doing that since it was the only solution I found, and if I don't want to see the navigation bar I just hide it – aryaxt Jun 01 '15 at 20:25

4 Answers4

4

Status bar color depends on the top view color of the view(View that is connected to the status bar).

If navigation bar is connected to the status bar then status bar takes the navigation bar.

if navigation bar is hidden then the top view that is connected to the status bar. that view color will be taken by the status bar.

So if navigation bar is not there then you should change the color of the view that is connected to the status bar.

Hope this help.

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
0

Implement this code when displaying the modal view to force the application to change style.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

Probably best in the Modals UIViewController

-(void)viewWillAppear:(BOOL)animated

In the applications plist you also need to set

View controller-based status bar appearance: NO

Chris
  • 2,727
  • 2
  • 27
  • 28
  • Doesn't do it. I called it in the viewDidLoad of my modal, and still looks the same, this should be the same as overriding preferredStatusBarStyle – aryaxt May 07 '14 at 02:54
  • The status bar is still white, and it has no content in it. All blank – aryaxt May 07 '14 at 02:58
  • This causes some really buggy issues where status bar randomly appears/disappears when using a MPMovieController anywhere in the app. – Jeremy White May 06 '15 at 04:27
0

Not sure if this is a good solution. How about trying something like:-

-(void)displayModal{
  AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
  view.backgroundColor=[UIColor grayColor];
  [delegate.window.rootViewController.view addSubview:view];
  [delegate.window makeKeyAndVisible];
}

-(void)dismissModal{
  AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
  view.backgroundColor=[UIColor whiteColor];
  [delegate.window.rootViewController.view addSubview:view];
  [delegate.window makeKeyAndVisible];
}
Ricky
  • 10,485
  • 6
  • 36
  • 49
0

Try setting the background color on the navigation controller's view:

let navController = UINavigationController(rootViewController: yourController)
navController.view.backgroundColor = UIColor.blue

// If you also want to set the navigation bar background color:
navController.navigationBar.backgroundColor = UIColor.blue
Swindler
  • 802
  • 10
  • 9