由于iOS13为深色模式,因此我正在Xamarin.Forms应用程序中对其进行支持。显示NavigationBar时,除了StatusBar颜色外,一切都正常。 Bar的通常行为是应将NavBar的BGColor相应地更改为backgroundColor,但是由于某些原因,它始终保持白色。
我试过像这样手动上色

UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString(“statusBar”))作为UIView;
statusBar.BackgroundColor = UIColor.FromRGB(61,205,88);

但这并没有改变任何东西。
下面是它的外观截图

ios - Xamarin.iOS statusBar BackgroundColor不会更改-LMLPHP

最佳答案

在Xamarin.Forms应用程序中,修改状态栏需要在iOS解决方案中编辑Info.plist

首先,将UIViewControllerBasedStatusBarAppearance添加到文件中:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
//Follow can change text color of status bar
//<key>UIStatusBarStyle</key>
//<string>UIStatusBarStyleDarkContent</string>

第二个,在Xamarin.iOS项目中,您可以在AppDelegate.cs中修改statsbar背景,如下所示:
public override void OnActivated(UIApplication uiApplication)
{
    if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
    {
        // If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
        // UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
        UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
        statusBar.BackgroundColor = UIColor.Red;
        statusBar.TintColor = UIColor.White;
        UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
    }
    else
    {
        UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
        if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
        {
            statusBar.BackgroundColor = UIColor.Red;
            statusBar.TintColor = UIColor.White;
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
        }
    }
    base.OnActivated(uiApplication);
}

您也可以看看this discussion

关于ios - Xamarin.iOS statusBar BackgroundColor不会更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58846419/

10-13 07:59