3
votes

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?

4
Is there simply not a solution to this? It's been a while since you asked, and no accepted answer?elsurudo
@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 itaryaxt

4 Answers

4
votes

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.

0
votes

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

0
votes

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];
}
0
votes

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