Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7: modal view controller status bar is wrong color but normal view controllers are correct

I have an issue in iOS7 where a normal UINavigationController pushed view controller has the correct status bar text color for the UINavigationController navbar color (which is a light gray, almost white so the status bar text is black). However, when a "modal" view controller is presented using -presentViewController:animated:completion:, the status bar text color is changed to white and is very hard to see given the color of the navbar. Navbar color is always the same across the whole app and does not change for each view controller. This happens on every -presentViewController call.

"View controller-based status bar appearance" is set to YES.

I am not sure what to look at to try and solve this.

like image 735
chadbag Avatar asked Dec 16 '13 19:12

chadbag


2 Answers

set YourModalViewControler.modalPresentationCapturesStatusBarAppearance to YES and keep "View controller-based status bar appearance" to YES.

- (void)viewDidLoad {     [super viewDidLoad];     self.modalPresentationCapturesStatusBarAppearance = YES;     .... } 

then overwrite preferredStatusBarStyle

- (UIStatusBarStyle)preferredStatusBarStyle {     return TheStyleYouWant; } 
like image 105
chie Avatar answered Sep 30 '22 04:09

chie


The navigation controller decides whether to have a light or dark content based on its navigation bar's barStyle property. The default, UIBarStyleDefault, means the navigation bar has a light color and the status bar will have dark content. Changing this property to UIBarStyleBlack doesn't actually make the navigation bar black (the color of the navigation bar is still set using barTintColor), but it tells it that it has a dark color. The navigation controller then decides that, since the navigation bar is dark, it should set the status bar content to light.

It appears that on your main navigation controller (on which you push things) the barStyle is indeed set to UIBarStyleBlack somewhere. You have to do the same thing to the modally presented navigation controller, like so:

UINavigationController *newViewController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
newViewController.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
[self presentViewController:newViewController animated:YES completion:nil];
like image 37
Scott Berrevoets Avatar answered Sep 30 '22 04:09

Scott Berrevoets