如何在ios中设置Xamarin.forms标签页未选中的图标和文字颜色

How to set the Xamarin.forms tab page unselected icon and text color in ios

我有一个 xamarin 表单应用程序,它有一个标签页(如图所示)。它将在 android 设备中显示是这样的。

ios中它看起来像这样。

您在 ios 中看到未选中的图标和文本的问题比 android 中的对应部分要沉闷一些。实际上,我通过将这些行放在标签页 xaml.

中来设置 android 中选中和未选中图标和文本的颜色
         android:TabbedPage.BarItemColor="#c4c0c0"
         android:TabbedPage.BarSelectedItemColor="#ffffff"

现在在 ios 中,我通过在 AppDelegate.cs

中添加这一行来设置所选颜色
 UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(255, 255, 255);

但是如何调整ios中未选中图标的颜色和文字颜色?我应该使用任何自定义渲染器吗?

在最新的 4.0 预发布版中,有两个适用于 iOS 和 Android 的新属性:

Color TabbedPage.UnselectedTabColorProperty { get; set; } //Bindable Property
Color TabbedPage.SelectedTabColorProperty { get; set; } //Bindable Property

在此处拉取请求: https://github.com/xamarin/Xamarin.Forms/pull/4899

对于旧版本,您必须使用自定义渲染器。例如,这是未选中时获得白色的代码:

TabBar.UnselectedItemTintColor = UIColor.FromRGBA(255, 255, 255, 255);

通常我在 ViewWillLayoutSubviews 覆盖中使用此代码来做其他事情,例如微管理标签栏高度、背景图像、ecc...

    public override void ViewWillLayoutSubviews()
    {
        base.ViewWillLayoutSubviews();

        TabBar.UnselectedItemTintColor = UIColor.FromRGBA(255, 255, 255, 255);

        //doing other customization stuff here

    }