【发布时间】:2020-03-25 07:45:48
【问题描述】:
我有 Xamarin Forms 应用程序。我不使用导航栏:
Xamarin.Forms.NavigationPage.SetHasNavigationBar(this, false);
我需要更改 iOS 状态栏中的颜色(背景)和文本颜色。我使用此代码:
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
statusBar.BackgroundColor = UIColor.White;
statusBar.TintColor = UIColor.Black;
statusBar.AccessibilityIgnoresInvertColors = true;
statusBar.TintColorDidChange();
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.White;
statusBar.TintColor = UIColor.Black;
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
}
}
我在 info.plist 中添加了这段代码:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
在此之后:状态栏背景代码 - 白色。但是文字颜色是白色的(我需要黑色)。 有什么建议吗?
【问题讨论】:
-
据我所知,你只能有白色或黑色。
-
我需要黑色。我编辑了我的答案。
-
@FetFrumos 嗨,如果回答有帮助,感谢您提前有时间标记或投票 *.^
标签: ios xamarin.forms xamarin.ios