将 Ionic 3 应用程序的 iOS 状态栏字体颜色更改为白色

Change iOS status bar font color to white for Ionic 3 app

我的config.xml

<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />

我的app.component

import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      statusBar.styleLightContent();
      splashScreen.hide();
    });
  }

没用。

如果您没有用于状态栏的 ng-cordova 插件。然后你可以这样做 -

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

也许你可以在你的 platform.ready().then(() => 方法中尝试这个

 StatusBar.overlaysWebView(false);
 StatusBar.backgroundColorByHexString('#00FFFF');

我找到了解决办法。对我有用

  statusBar.overlaysWebView(true);
  statusBar.backgroundColorByHexString('#1f2933');
this.statusBar.backgroundColorByHexString('transparent');

在我的例子中,我需要更改 IOS 中的状态栏背景颜色和内容颜色。

首先我需要安装插件。

ionic cordova plugin add cordova-plugin-statusbar
npm install --save @ionic-native/status-bar@4 // version 4 since ionic 3

然后 在 app.comopenet.ts

  constructor(statusBar: StatusBar, platform: Platform) {
      platform.ready().then(() => {

          statusBar.overlaysWebView(false);
          // overlaysWebView must set to false if you change the background color in iOS with ionic (hence I am using backgroundColorByHexString method )

          statusBar.backgroundColorByHexString('#c8102e');
          // used above hex color code to set the status bar background color 

          statusBar.styleLightContent();
          // above function  will change the status bar content (icon , text)

          statusBar.show();
          // finally shows the status bar
      });
  }

我终于得到了我需要的东西