如何在 iOS 7 上启动时更改状态栏样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18924345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:28:57  来源:igfitidea点击:

How to change status bar style during launch on iOS 7

iosobjective-cios7

提问by user1008096

When I launch my app, it shows the launch image and a black status bar. How can I change it so the status bar is light during launch? I have set the status bar appearance to light in my AppDelegate didFinishLoading method, and it works for the rest of the app.

当我启动我的应用程序时,它会显示启动图像和黑色状态栏。如何更改它以便在启动期间状态栏亮起?我已在 AppDelegate didFinishLoading 方法中将状态栏外观设置为亮起,并且它适用于应用程序的其余部分。

回答by Tricertops

To your Info.plistfile add this key-value pair:

在您的Info.plist文件中添加此键值对:

UIStatusBarStyle: UIStatusBarStyleLightContent

The default (black) value is UIStatusBarStyleDefault.

默认(黑色)值为UIStatusBarStyleDefault

You can also append ~iphoneor ~ipadto the key.

您还可以将~iphone或附加~ipad到键。

回答by samwize

There are 2 steps:

2个步骤

  1. This is usually what developers know how to do – Under Target settings > General > Status Bar Style > Change to Light. This will effect the Info.plist to include UIStatusBarStyleLightContent.

  2. This step is often missed out– In Info.plist, add View controller-based status bar appearanceand set to NO

  1. 这通常是开发人员知道如何做的 - 在目标设置 > 常规 > 状态栏样式 > 更改为浅色下。这将影响 Info.plist 以包含UIStatusBarStyleLightContent.

  2. 这一步经常被遗漏——在Info.plist中,添加View controller-based status bar appearance并设置为NO

回答by Mohit Tomar

Just define this method in any view or file you want:

只需在您想要的任何视图或文件中定义此方法:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

// swift 
override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}

回答by BalestraPatrick

In my case, UIStatusBarStyleLightContentwasn't a possible option. I set Transparent black style (alpha of 0.5)as value for the key Status bar stylein my .plist and the result was a white status bar.

就我而言,UIStatusBarStyleLightContent这不是一个可能的选择。我将.plist 中Transparent black style (alpha of 0.5)的键设置为值,Status bar style结果是一个白色的状态栏。

回答by Pavel Volobuev

Works on iOS7 and iOS8

适用于 iOS7 和 iOS8

You need to set in your Info.plistfile property for key Status bar style:

您需要在Info.plist文件属性中为 key 设置 Status bar style

  1. Set Opaque black styleor Transparent black style (alpha of 0.5)for Whitestatus bar
  2. Set Gray style (default)to set Blackstatus bar color.
  1. 设置Opaque black styleTransparent black style (alpha of 0.5)白色状态栏
  2. 设置Gray style (default)为设置黑色状态栏颜色。

It looks like you set Background style for Status Bar and XCode understand which color of status bar need to choose. Dark background - white status bar, light background - black status bar

看起来您为状态栏设置了背景样式,XCode 了解需要选择哪种颜色的状态栏。深色背景 - 白色状态栏,浅色背景 - 黑色状态栏

回答by rahulchona

**

 - You must take care of these three things:

**

**- In info.plist file**
Set UIViewControllerBasedStatusBarAppearance to YES

**- In your view controller** in which you want change color of status bar
add this [self setNeedsStatusBarAppearanceUpdate] in viewDidLoad

**- Lastly, add this method**
- (UIStatusBarStyle)preferredStatusBarStyle
{
      return UIStatusBarStyleLightContent;
}

Note: If you want to set color of statusBar for all the View Controllers then steps are
**- In info.plist file**
Set UIViewControllerBasedStatusBarAppearance to YES

**- Then add this in appDelegate**
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; // **It is deprecated in iOS 9**