ChatGPT解决这个技术问题 Extra ChatGPT

Changing the status bar text color in splash screen iOS 7

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

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

In the application:DidFinishLaunching

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

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

What do you mean 'it still shows the status bar with the black color' : If your code works, status bar font should be white, status bar background color depends on your splash image (which should now include status bar height - 20 pixels)
Sorry, I really missed the text word. I am changing only the text color of the status bar. I can change it after the splash screen happens but I can't change it when the splash screen is happening.

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

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


Is there any way to make this compatible with a tinted status bar on iOS 6 ?
Text color of status bar is either white, or black. The background of the bar comes from your launch image, then from your viewController's view if it extends below bars.
After TONS of different methods, this one FINALLY worked (with UIViewControllerBasedStatusBarAppearance set to NO). You are a hero.
you can also do this via code UIApplication.sharedApplication().statusBarStyle = .LightContent. I do it in AppDelegate
@Yasmin : to changer color AFTER the splash screen, this solution was already part of the question ;)
L
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 plist file:

Status bar style: UIStatusBarStyleLightContent

View controller-based status bar appearance: NO

Status bar is initially hidden: NO


The accepted answer is good, but it didn't work on all my view controllers without doing the 2nd bullet above. Thanks!
"View controller-based status bar appearance: YES" still seems to do the trick (iOS 9)
A
Anooj VM

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

In your plist file add the following values:

Status bar style - UIStatusBarStyleLightContent 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.


T
Tiago Almeida

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


this is showing white text on status bar while my background is also light. how can I show black text
Mangesh on the Target go to the general settings there you will have a option to set the status bar style
You could actually write that first line a little bit simpler using dot syntax, like this: if (UIDevice.currentDevice.systemVersion.floatValue >= 7) {
K
Krunal

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:

Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file, if you need to set status bar style at UIViewController level only. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate override preferredStatusBarStyle in your view controller.

-

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

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

https://i.stack.imgur.com/8sH5i.png

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:

https://i.stack.imgur.com/LKppl.png


U
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