Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set status bar's content color to white on iOS 7

My App’s background colour is black. Cause the whole view is below the status bar on iOS 7, the content on the status bar will hard to be distinguished. So how to change status bar’s content colour to white?

I've tried preferredStatusBarStyle and several other ways, but failed.

like image 937
Kjuly Avatar asked Sep 23 '13 07:09

Kjuly


People also ask

How do I change the color of my status bar on my Iphone?

Go to the Storyboard. Select the View and in the Attributes Inspector change the Background Color to Light Gray. Build and Run the Project. The default style of the status bar is dark content.

How can I change the color of my status bar?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.

How do I change the color of text in status bar in Objective C?

Go to Project -> Target , Then set Status Bar Style to Light . It makes status-bar white from the launch screen. Then set View controller-based status bar appearance equal to NO in Info.

What is the IOS status bar?

A status bar appears along the upper edge of the screen and displays information about the device's current state, like the time, cellular carrier, and battery level.

How to change the color of the status bar to white?

The default color of the status bar is black text. To change the status bar to white: Open you Info.plist. Add View controller-based status bar appearance key ( UIViewControllerBasedStatusBarAppearance) and set value to No ( false ). Add Status bar style key ( UIStatusBarStyle) and set value to Light Content ( UIStatusBarStyleLightContent ).

How to change the status bar content to light in Swift?

The default style of the status bar is dark content. The style of the status bar can be changed to a status bar with white content. Go to the ViewController.swift file and add the following lines of code. The preferredStatusBarStyle property is set to lightContent. Build and Run the project to see the content of the status bar changed to light.

Why is the status bar dark in my iOS project?

Build and Run the project, The content of the status bar is dark again, which is the default. The reason for this is, iOS asked for the style of the status bar of the navigation controller instead of the contained view controller.

Why is my Blazor content white on iOS?

This really doesn’t have much to do with the fact that it’s .NET MAUI, this is just how iOS works. It’s not just white, it’s transparent even. If you scroll the Blazor content all the way to the top you can see the content appearing above the top bar of our Blazor content.


1 Answers

  1. Set "View controller-based status bar appearance” to NO in your info.list file;
  2. Insert

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

    to -application:didFinishLaunchingWithOptions: of the AppDelegate.m.


Note: UIStatusBarStyleDefault is the default value for the status bar style, it'll show black content instead. Both UIStatusBarStyleBlackTranslucent & UIStatusBarStyleBlackOpaque are deprecated in iOS 7.0.


UPDATE for iOS 9:

As @ZakariaDarwish mentioned, the method -setStatusBarStyle is deprecated in iOS 9. (Note: The original question was asked for iOS 7 long time ago, and I don't support it now, the new solution below works for me under iOS 9, hence update here.)

So, the only way left (at least for now) is to implement -preferredStatusBarStyle in your view controller (remember to set "View controller-based status bar appearance" back to YES).

You can invoke UIViewController's instance method -setNeedsStatusBarAppearanceUpdate once value changed in -preferredStatusBarStyle or -prefersStatusBarHidden.

There're also two methods -childViewControllerForStatusBarStyle & -childViewControllerForStatusBarHidden to return the preferred style from child view controller as you want.

e.g., if you used below methods

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; 

to switch status bar style before, you can use code sample below

- (void)shouldChangeStatusBarStyleToLightContent:(BOOL)toLightContent                                         animated:(BOOL)animated {   _shouldChangeStatusBarStyleToLightContent = toLightContent;   if (animated) {     [UIView animateWithDuration:.3f animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }];   } else {     [self setNeedsStatusBarAppearanceUpdate];   } }  - (UIStatusBarStyle)preferredStatusBarStyle {   return (_shouldChangeStatusBarStyleToLightContent ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault); } 

for this updated solution now.

like image 105
Kjuly Avatar answered Sep 28 '22 23:09

Kjuly