iOS 7: modal view controller status bar is wrong c

2019-03-14 15:31发布

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.

9条回答
Melony?
2楼-- · 2019-03-14 16:05

I just figured out how to do that. I had the exact same problem and it seems that it works like a charm!

The first thing you need to do is to change an attribute in you .plist file of your project to NO. The attribute is: "View controller-based status bar appearance". If the attribute doesn't exist, don't hesitate to add a new one exactly as I just written to you (without quotes).

The second thing is to add to each view controller's viewDidLoad method

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

if you want your status bar's text to be white or

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

if you want your status bar's text to be black.

That's all!

查看更多
虎瘦雄心在
3楼-- · 2019-03-14 16:09

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;
}
查看更多
虎瘦雄心在
4楼-- · 2019-03-14 16:09

Having reviewed all the answers provided here and in other answers, I have found that the only solution that worked for me was to create a vacuous navigation bar for the view controller I am presenting modally.

This may not work for you, but it works for me for the following reasons:

  1. My modal dialog has a navigation bar anyways (although it is not used for navigation; it is simply used to either save or dismiss the results.
  2. The status bar color has already been defined application-wide in applicationDidFinishLaunching as discussed above, and it has a custom colour.

It's somewhat annoying from an engineering perspective to have a navigation controller that effectively does nothing, but without one I was unable to get past this problem.

查看更多
登录 后发表回答