使用 TabbedPage 时更改所选 NavigationPage 上的 "Active" 图标

Change "Active" icon on selected NavigationPage when using TabbedPage

我对 Xamarin.Forms 非常非常陌生。我的任务,如果可能的话,我不确定它是否是,是在我们的图标处于活动状态时将其从默认蓝色更改。

我得到的图标是橙色的,他们希望显示这些图标或至少显示颜色而不是默认的蓝色。同样,我不确定这是否可能。

这是我用于标签页的代码。

public class LandingPage : TabbedPage
{
    public LandingPage ()
    {
         NavigationPage homepage = new NavigationPage (new CarouselPage {
                Title = "Title",
                Children = {
                  //code removed 
                }
        });

        NavigationPage eventspage = new NavigationPage (new ContentPage {
                Title = "Calendar Event List",
                Content = new EventList ()
        });
        NavigationPage morepage = new NavigationPage (new MorePage ());

        homepage.BarBackgroundColor = Device.OnPlatform (Color.FromHex (DependencyService.Get<IContentStrings>().BarBackgroundColor), Color.Transparent, Color.Transparent);
        homepage.BarTextColor = Color.FromHex(DependencyService.Get<IContentStrings>().BarTextColor);
        homepage.Title = DependencyService.Get<IContentStrings>().HomeTitle;
        homepage.Icon = DependencyService.Get<IContentStrings>().HomeImage;

        eventspage.BarBackgroundColor = Device.OnPlatform (Color.FromHex (DependencyService.Get<IContentStrings>().BarBackgroundColor), Color.Transparent, Color.Transparent);
        eventspage.BarTextColor = Color.FromHex(DependencyService.Get<IContentStrings>().BarTextColor);
        eventspage.Title = DependencyService.Get<IContentStrings>().EventTitle;
        eventspage.Icon = DependencyService.Get<IContentStrings>().EventImage;

        morepage.BarBackgroundColor = Device.OnPlatform (Color.FromHex (DependencyService.Get<IContentStrings>().BarBackgroundColor), Color.Transparent, Color.Transparent);
        morepage.BarTextColor = Color.FromHex(DependencyService.Get<IContentStrings>().BarTextColor);
        morepage.Title = DependencyService.Get<IContentStrings>().MoreTitle;
        morepage.Icon = DependencyService.Get<IContentStrings>().MoreImage;

        Children.Add (homepage);
        Children.Add (eventspage);
        Children.Add (morepage);
    }       
}

我不确定我是否能够使用自定义渲染器或其他任何东西。我不知道我是否有任何选择,非常感谢任何指导!

您可以使用简单的自定义 iOS 渲染器设置活动标签图标颜色,如下所示:

[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedPageRenderer))]
namespace MyApp.iOS.Renderers
{
    public class MyTabbedPageRenderer : TabbedRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            TabBar.TintColor = UIColor.Orange;
        }
    }
}

我发现在互联网上搜索几个小时后终于找到了答案,然后在另一天返回到该应用程序。要更改默认的蓝色,我更改了 AppDelegate 中的 UITabbar 色调颜色。

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    UIApplication.SharedApplication.SetStatusBarStyle (UIStatusBarStyle.LightContent, false);
    global::Xamarin.Forms.Forms.Init ();

    LoadApplication (new App ());

    //this changes the default iOS tintcolor for the icon when it's activated
    UITabBar.Appearance.TintColor = UIColor.FromRGB(223, 112, 13);

    return base.FinishedLaunching (app, options);

}