【发布时间】:2020-03-09 20:55:02
【问题描述】:
在我的 Xamarin.Forms 4.4 项目中,我使用以下代码将导航栏的全局颜色定义为带有白色文本的纯橙色::
UINavigationBar.Appearance.BackgroundColor = UIColor.Orange;
UINavigationBar.Appearance.BarTintColor = UIColor.Orange;
UINavigationBar.Appearance.TintColor = UIColor.White;
UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes()
{
ForegroundColor = UIColor.White
};
自从将我的 Xamarin.Forms NuGet 包从 4.4 升级到 4.5 后,我在 iOS 13 中运行的任何应用程序在浅色模式下都有一个带有白色文本的纯白色导航栏。
我知道有一些新的类可用于 iOS 13。但是,我不明白如何使用这些类在 iOS 13 中获得相同的外观(或只是可读的东西)。这就是我所拥有的试过了:
UINavigationBarApperance nba = new UINavigationBarAppearance();
nba.ConfigureWithOpaqueBackground();
nba.BackgroundColor = UIColor.Orange;
nba.BarTintColor = UIColor.Orange;
nba.TintColor = UIColor.White;
UINavigationBar.Appearance.ScrollEdgeAppearance = nab;
UINavigationBar.Appearance.StandardAppearance = nab;
UINavigationBar.Appearance.CompactAppearance = nab;
这是我的结果:
我实际上可以看到一些颜色渗出似乎是白色渐变叠加层。我怀疑深灰色是我选择的颜色上的深色渐变的结果
【问题讨论】:
-
Xamarin 使用与原生 XCode 解决方案相同的 iOS API。另见github.com/xamarin/xamarin-macios/issues/6834
-
我刚刚在一个空白的 Forms iOS 应用程序中尝试了您的代码,并且成功了。但是,如果我在现有的表单应用程序中尝试使用表单代码自定义导航栏,则它不起作用。你确定你没有在表单代码中做任何会影响导航栏的事情吗?
-
您可以在 Xamarin.Forms 中分享一些关于
NavigationPage的 Xaml 代码,这将有助于找到问题所在。
标签: c# xamarin xamarin.forms xamarin.ios