更改初始屏幕 iOS 7 中的状态栏文本颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18897362/
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:23:11  来源:igfitidea点击:

Changing the status bar text color in splash screen iOS 7

iosios7splash-screenstatusbaruistatusbar

提问by Tiago Almeida

I know that are already some stackoverflowquestionsthat say how to change the status bar for all view controllers. I am currently changing the color of status bar this way:

我知道已经有一些stackoverflow问题说明了如何更改所有视图控制器的状态栏。我目前正在以这种方式更改状态栏的颜色:

if(IS_IOS7)
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

In the application:DidFinishLaunching

在里面 application:DidFinishLaunching

Additionally, I have changed the value of UIViewControllerBasedStatusBarAppearancein the plist to NO. However, in the splashscreen it stills shows the status bar text with the black color.

此外,我已将UIViewControllerBasedStatusBarAppearanceplist 中的值更改为NO. 但是,在启动画面中,它仍然以黑色显示状态栏文本。

Is it possible to change the color of the status bar text color in the splash screen?

是否可以更改初始屏幕中状态栏文本颜色的颜色?

回答by Vinzzz

In the project plist file add the "Status Bar Style" property (key is UIStatusBarStyle). Then ignore all the possible values listed in the drop down for this property and type UIStatusBarStyleLightContentinstead.

在项目 plist 文件中添加“状态栏样式”属性(键是UIStatusBarStyle)。然后忽略此属性下拉列表中列出的所有可能值并键入UIStatusBarStyleLightContent

And you don't have to set UIViewControllerBasedStatusBarAppearanceto NOin your plist, you can set the preferredStatusBarStyleyou want to your view controllers.

而且您不必在 plist 中设置UIViewControllerBasedStatusBarAppearanceNO,您可以将preferredStatusBarStyle您想要的设置为您的视图控制器。

回答by Lucas

You can do this without writing any line of code
Do the following to make the status bar text color white through the whole app

您可以在不编写任何代码行的情况下执行此操作
执行以下操作以使整个应用程序的状态栏文本颜色为白色

On you project plistfile:

在您的项目 plist文件中:

  • Status bar style: UIStatusBarStyleLightContent
  • View controller-based status bar appearance: NO
  • Status bar is initially hidden: NO
  • 状态栏样式: UIStatusBarStyleLightContent
  • 查看基于控制器的状态栏外观: NO
  • 状态栏最初是隐藏的: NO

回答by Anooj VM

You can do the following things for getting light color status bar throughout the application.

您可以执行以下操作以在整个应用程序中获取浅色状态栏。

  1. Select the name of the project in the project navigator.
  2. Select the name of a target from the list in the left column of the project editor.
  3. Click General at the top of the project editor.
  4. Set Status Bar Style -> Light
  1. 在项目导航器中选择项目名称。
  2. 从项目编辑器左列的列表中选择目标的名称。
  3. 单击项目编辑器顶部的常规。
  4. 设置状态栏样式 -> Light

In your plist file add the following values:

在您的 plist 文件中添加以下值:

  1. Status bar style - UIStatusBarStyleLightContent
  2. View controller-based status bar appearance - NO
  1. 状态栏样式 - UIStatusBarStyleLightContent
  2. 查看基于控制器的状态栏外观 - 否

This will help you to get the status bar in WHITE colour throughout the application including SPLASH SCREEN.

这将帮助您在整个应用程序(包括闪屏)中获得白色状态栏。

回答by Preejith augustine

Set the UIViewControllerBasedStatusBarAppearanceto No in the plist

UIViewControllerBasedStatusBarAppearance在 plist 中设置为 No

Then add the following code in did finish launch option

然后在 did finish 启动选项中添加以下代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

   [application setStatusBarStyle:UIStatusBarStyleLightContent];

    self.window.clipsToBounds =YES;

    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}

Please follow this code it worked for me

请按照此代码对我有用

回答by Krunal

Here is Apple Guidelines/Instructionabout status bar change.

这是有关状态栏更改的Apple 指南/说明

Here is - How to change status bar style:

这是 - 如何更改状态栏样式:

If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearanceto NOin your `.plist' file.

如果你想设置状态栏样式,应用的水平,那么设置UIViewControllerBasedStatusBarAppearanceNO你的`的.plist”文件。

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

如果您想设置状态栏样式,请在视图控制器级别执行以下步骤:

  1. Set the UIViewControllerBasedStatusBarAppearanceto YESin the .plistfile, 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.

  1. 设置UIViewControllerBasedStatusBarAppearanceYES.plist文件,如果需要设置状态栏样式仅UIViewController的水平。
  2. 在 viewDidLoad 添加函数 - setNeedsStatusBarAppearanceUpdate

  3. 覆盖视图控制器中的 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. enter image description here

根据状态栏样式设置级别设置 .plist 的值。 在此处输入图片说明


You can set background color for status bar during application launch or during viewDidLoad of your view controller.


您可以在应用程序启动期间或视图控制器的 viewDidLoad 期间设置状态栏的背景颜色。

extension UIApplication {

    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }

}

// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
        return true
    }
}


or 
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
    }

}



Here is result:



这是结果:

enter image description here

在此处输入图片说明

回答by Usman Nisar

You can do the following things for getting light color status bar throughout the application.

您可以执行以下操作以在整个应用程序中获取浅色状态栏。

Select the name of the project in the project navigator. Select the name of a target from the list in the left column of the project editor. Click General at the top of the project editor. Set Status Bar Style -> Light

在项目导航器中选择项目名称。从项目编辑器左列的列表中选择目标的名称。单击项目编辑器顶部的常规。设置状态栏样式 -> Light