如何在13-Xamarin Forms下的IOS版本中更改状态栏图标的颜色?

问题描述

我只能在Xamarin Forms App的13下的IOS版本中更改状态栏图标的颜色。我已经这样做了,并且可以在13以上的IOS版本上很好地工作。我可以更改背景颜色,但是我不需要它,我需要图标本身。

看例子: 这段代码仅用于更改状态栏BackgroundColor,我设置了status.TintColor,但它不会更改...

private void ChangeStatusBar()
    {
        UIView statusBar = UIApplication.SharedApplication.ValueForKey(new Nsstring("statusBar")) as UIView;
        if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
        {
            statusBar.BackgroundColor = UIColor.White;
            statusBar.TintColor = UIColor.White;
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
        }
    }

在13以上的IOS版本中,我使用它来更改状态栏图标的颜色,并且可以正常工作:

 UIApplication.SharedApplication.SetStatusBarStyle(isLightTheme ? UIStatusBarStyle.LightContent : UIStatusBarStyle.DarkContent,false);
            GetCurrentViewController().SetNeedsstatusBarappearanceUpdate();

解决方法

确保已在info.plist中添加了键值描述

View controller-based status bar appearance(默认值为是)。

enter image description here