问题
I can't work out how to change IOS's status bar in nativescript without the requirement of having an ActionBar / NavigationBar.
I've tried:
var navController = frame.topmost().ios.controller;
let navigationBar = navController.navigationBar;
navigationBar.barStyle = UIBarStyle.Black;
But this totally fails when there is no ActionBar!
回答1:
This solution works!
Step 1:
Add the below to app/App_Resources/iOS/Info.plist
.
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
It will do the following:
- Set default color for the splash screen and app to white.
- Allow you to change the status bar color within the app.
Step 2:
After adding that you can then use the below snippet to change the status bar style color:
// white status bar text
UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.LightContent, true);
// black status bar text
UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.Default, true);
Optional But Important Step 3:
If you want to change the status bar as soon as the application finishes loading (after splash screen) or when it becomes active then you'll need to set the above snippet inside a UiApplicationDelegate
function. See link for example:
https://docs.nativescript.org/core-concepts/application-lifecycle#ios-uiapplicationdelegate
来源:https://stackoverflow.com/questions/57555115/how-to-change-the-status-bar-color-in-ios-without-an-actionbar-in-nativescript