简体   繁体   English

即使设置为亮,状态栏仍保持黑色

[英]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. 我有与Swift中的iPad和iPhone兼容的应用程序,使用XCode 6.4支持iOS 7和8。 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! 在情节提要中,所有控制器均显示白色状态栏(主,详细信息,导航控制器...),但在模拟器中或iPhone / iPad中均不显示白色,而是黑色!

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). 尝试添加plist选项,该选项允许我为每个视图控制器设置(请注意,我不想为每个控制器控制状态栏颜色,而是为应用程序设置全局颜色)。 Also tried to set override function for status bar style and even reload function in viewDidLoad func. 还尝试为状态栏样式设置覆盖功能,甚至在viewDidLoad函数中设置重载功能。 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). 我以为只要在拆分控制灯状态栏中设置,其他地方它都会继承它(这就是它在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 这是演示代码: https : //goo.gl/U3Ynbc

Many thanks in advance! 提前谢谢了!

In your Info.plist , add the "View controller-based status bar appearance" to YES . 在您的Info.plist ,将“基于View Controller的状态栏外观”添加到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() 在plist中,将“基于视图控制器的状态栏外观”设置为NO,然后在func应用程序中的appDelegate.swift中返回true之前,添加以下行: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". 与发问者具有相同的经验(将.storyboard中的值设置为“ Light Content”,并尝试在多个位置针对使用splitView的应用程序更改了此值,然后在模拟器中看到statusBar前景白色),我在检查情节提要的XML时发现它们是“模拟指标”。

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. 当我将值UIStatusBarStyle添加到Info.plist并将其设置为UIStatusBarStyleLightContent (这不是显示的选项之一),然后运行时,状态栏样式正确显示。 (and that was after deleting all of the simulated metrics changes i had placed in the .storyboard file). (那是在删除我放置在.storyboard文件中的所有模拟指标更改之后)。

If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance to NO in your .plist file. 如果要设置状态栏样式,请在应用程序级别将.plist文件中的UIViewControllerBasedStatusBarAppearance设置为NO

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. 如果仅需要在UIViewController级别设置状态栏样式,则在.plist文件中将UIViewControllerBasedStatusBarAppearance设置为YES
  2. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate 在viewDidLoad中添加函数setNeedsStatusBarAppearanceUpdate

  3. override preferredStatusBarStyle in your view controller. 在视图控制器中重写preferredStatusBarStyle。

- -

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

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

Set value of .plist according to status bar style setup level. 根据状态栏样式设置级别设置.plist的值。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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