How to change the status bar color in IOS without an Actionbar in Nativescript?

梦想的初衷 提交于 2019-12-24 06:34:01

问题


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:

  1. Set default color for the splash screen and app to white.
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!