2

I am working on a Xamarin forms project.

I have a tabbed page with 9 tabs. 4 tabs would show with description and icon in tab bar, and there is extra tab is added "More" which contains list of other tabs.

In Appdelegate.cs file I set

UITabbar.appearance.SelectedImageTintColor = UIColor.green;

And also this is my Custom tab renderer:

 public class CustomTabRenderer : TabbedRenderer
{
    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);
        TabBar.TintColor = new UIColor(red: 0.55f, green: 0.76f, blue: 0.29f, alpha: 1.0f);
    }

    public override void ViewDidAppear(bool animated)
    {
        base.ViewDidAppear(animated);
        if (TabBar.Items == null) return;
        TabBar.SelectedImageTintColor = new UIColor(red: 0.55f, green: 0.76f, blue: 0.29f, alpha: 1.0f);
        foreach (var uiTabBarItem in TabBar.Items)
        {
            var fontSize = new UITextAttributes(){ Font = UIFont.SystemFontOfSize(13)};
            uiTabBarItem.SetTitleTextAttributes(fontSize, UIControlState.Normal);

        } 
    }

    public override void ItemSelected(UITabBar tabbar, UITabBarItem item)
    {
        tabbar.SelectedImageTintColor = new UIColor(red: 0.55f, green: 0.76f, blue: 0.29f, alpha: 1.0f);
    }

So all the 4 tabs on the bar bar are green color, but the tabs in "More" Section are always blue.

Any solution please? Also can we put colored images into tab bar?

jamesfdearborn
  • 769
  • 1
  • 10
  • 26
Sai Sunkari
  • 179
  • 3
  • 27

1 Answers1

1

First, tabbar can display only 5 item at most in iOS . if you want to change the color of the item "More" use the code

    UITabBarController  tabViewController = (UITabBarController)this.Window.RootViewController;
    tabViewController.MoreNavigationController.TabBarController.TabBar.TintColor =new UIColor(red: 0.55f, green: 0.76f, blue: 0.29f, alpha: 1.0f);

after you set the tabbar

Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22
  • The above class is the custom renderer. And i have page which extends Tabbed page. In this page's OnAppearing();I am setting the pages as Tab tab = new Tab { Title = "test" , Icon = "test.png"}. Where to set the above lines. Unable to access above methods in Tabbed page and customRenderer. @X.Joe – Sai Sunkari Aug 20 '18 at 17:52