简体   繁体   中英

Status bar stays black even when set to light

I have app compatible with iPad and iPhone in Swift, supporting iOS 7 and 8, using XCode 6.4. Now I made app structured as master-detail control and set in split controller status bar to be light (white). In Storyboard, all controllers display white status bar (master, detail, navigation controllers...) but nor in simulator nor in iPhone / iPad is white but black!

I tried in each controller and its navigator controller to set light status bar. Tried in Master view controller to set it. Tried to add in plist option that allows me setting up per view controller (note that I do not want to control status bar color per controller but to set global for the app). Also tried to set override function for status bar style and even reload function in viewDidLoad func. And nothing worked.

I am really stuck here; I thought just set in split control light status bar and everywhere else it inherits it (and that's how it indeed looks in stoyboard). So what am I missing? Can anyone help me out or give me some hints or directions in further investigation?

Here is demo code: https://goo.gl/U3Ynbc

Many thanks in advance!

In your Info.plist , add the "View controller-based status bar appearance" to YES .

Then, in your view controller subclass, override this method:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

Ok found it. In plist set "View controller-based status bar appearance" to NO and in appDelegate.swift in func application before return true add following line: splitViewController.navigationController?.navigationBar.tintColor = UIColor.whiteColor()

having had the same experience as the questioner (seeing the statusBar foreground white in the simulator after having set the values in the .storyboard to "Light Content", and having tried changing this in several places for an app that uses a splitView), i discovered upon inspecting the XML of the storyboard that these were "simulated metrics".

when i added the value UIStatusBarStyle to my Info.plist, and set it to UIStatusBarStyleLightContent (which was not one of the options presented), then ran, the status bar style appeared correctly. (and that was after deleting all of the simulated metrics changes i had placed in the .storyboard file).

If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance to NO in your .plist file.

if you wan to set status bar style, at view controller level then follow these steps:

  1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file, if you need to set status bar style at UIViewController level only.
  2. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate

  3. override preferredStatusBarStyle in your view controller.

-

override func viewDidLoad() {
    super.viewDidLoad()
    self.setNeedsStatusBarAppearanceUpdate()
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

Set value of .plist according to status bar style setup level. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM