ios - Xamarin.iOS statusBar BackgroundColor不会更改

标签 ios xamarin.forms xamarin.ios ios13

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

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

screenshot

最佳答案

在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/

相关文章:

ios - Xamarin iOS 7 : Native linking failed

xamarin.ios - UIActivityIndi​​catorView.StartAnimating 重写 UIActivityIndi​​catorView.Hidden 绑定(bind)

ios - 如何以与 iPhoto 相同的方式订购 ALAssetsGroup

ios - UICollectionView 水平分页不居中

iphone - 最大 CAShapeLayer 大小?

xamarin - 使用 Xamarin.Forms 自定义导航

android - Xamarin Forms Android App 一直隐藏操作栏

iphone - 如何在不更改 iPhone 应用程序中的设备方向的情况下更改应用程序的方向

Xamarin 形成图像的固定大小

iphone - MonoTouch - 有人用过这个吗?