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

时间:2013-09-20 19:22:55

标签: ios objective-c ios7

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

6 个答案:

答案 0 :(得分:109)

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

UIStatusBarStyle: UIStatusBarStyleLightContent

默认(黑色)值为UIStatusBarStyleDefault

您还可以将~iphone~ipad附加到密钥。

答案 1 :(得分:19)

2 steps

  1. 这通常是开发人员知道如何操作 - 在目标设置>一般>状态栏样式>变为光明。这将使Info.plist包含UIStatusBarStyleLightContent

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

答案 2 :(得分:11)

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

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

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

答案 3 :(得分:3)

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

答案 4 :(得分:2)

适用于iOS7和iOS8

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

  1. 白色状态栏设置Opaque black styleTransparent black style (alpha of 0.5)
  2. 设置Gray style (default)以设置黑色状态栏颜色。
  3. 看起来您为状态栏设置了背景样式,XCode了解状态栏的哪种颜色需要选择。黑暗的背景 - 白色状态栏,浅色背景 - 黑色状态栏

答案 5 :(得分:0)

**

 - 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**
相关问题