在 iOS7启动画面中更改状态栏文本颜色

我知道已经有一些 堆栈溢出 问题说如何更改所有视图控制器的状态栏。我目前正在改变颜色的状态栏这样:

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

application:DidFinishLaunching

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

是否可以更改状态栏文本颜色 在启动屏幕上的颜色?

46107 次浏览

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 UIStatusBarStyleLightContent instead.

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

Set the UIViewControllerBasedStatusBarAppearance to No in the plist

Then add the following code in did finish launch option

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

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 plist file:

  • Status bar style: UIStatusBarStyleLightContent
  • View controller-based status bar appearance: NO
  • Status bar is initially hidden: NO

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

In your plist file add the following values:

  1. Status bar style - UIStatusBarStyleLightContent
  2. View controller-based status bar appearance - NO

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

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

Here is Apple Guidelines/Instruction about status bar change.

Here is - How to change status bar style:

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. enter image description here


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

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