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.
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.
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.
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.
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.
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 ).
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With