如何在没有Nativescript中的动作栏的情况下在IOS中更改状态栏颜色? [英] How to change the status bar color in IOS without an Actionbar in Nativescript?

查看:78
本文介绍了如何在没有Nativescript中的动作栏的情况下在IOS中更改状态栏颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有ActionBar/NavigationBar的要求,我无法解决如何在本机脚本中更改IOS的状态栏.

I can't work out how to change IOS's status bar in nativescript without the requirement of having an ActionBar / NavigationBar.

我尝试过:

var navController = frame.topmost().ios.controller;
let navigationBar = navController.navigationBar;
navigationBar.barStyle = UIBarStyle.Black;

但是,当没有ActionBar时,这将完全失败!

But this totally fails when there is no ActionBar!

推荐答案

此解决方案有效!

将以下内容添加到app/App_Resources/iOS/Info.plist.

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

它将执行以下操作:

  1. 将初始屏幕和应用程序的默认颜色设置为白色.
  2. 允许您在应用程序中更改状态栏的颜色.


步骤2:

添加后,您可以使用下面的代码段更改状态栏样式的颜色:


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);


可选但重要的步骤3:

如果您想在应用程序完成加载后(在启动屏幕之后)或当它变为活动状态时更改状态栏,则需要在UiApplicationDelegate函数中设置上面的代码段.例如,请参见链接:


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

这篇关于如何在没有Nativescript中的动作栏的情况下在IOS中更改状态栏颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆