【问题标题】:Xamarion.iOS - statusBar how change text color?Xamarin.iOS - 状态栏如何更改文本颜色?
【发布时间】: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


【解决方案1】:

在此之后:状态栏背景代码 - 白色。但是文字颜色是白色的(我需要黑色)。有什么建议吗?

在iOS中,你可以更改UIStatusBarStyle来修改状态栏的文字颜色。样式一共有三种,实际上是两种样式。(默认为深色,与深色风格。)

  • UIStatusBarStyleDefault:深色状态栏,用于浅色背景。

  • UIStatusBarStyleLightContent:浅色状态栏,用于深色背景。

  • UIStatusBarStyleDarkContent:深色状态栏,用于浅色背景。

如果需要在iOS中设置状态栏的黑色文字颜色,可以在Info.plist中添加follow key-value

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

【讨论】:

  • 感谢您提供详细信息。这对我帮助很大。
猜你喜欢
  • 2017-11-03
  • 2019-10-27
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 1970-01-01
  • 2019-01-13
相关资源
最近更新 更多