Search code examples
xamarin.formsxamarin.androidxamarin.iostabbedpage

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


I have a xamarin forms application which have a tab page(shown in image).It will show in android devices is like this. enter image description here

In ios it will look like this. enter image description here

The problem as you can see the unselected icon and text in ios is bit duller than android counterpart. I actually set the color of selected and unselected icon and text in android by putting these lines in tab page xaml.

         android:TabbedPage.BarItemColor="#c4c0c0"
         android:TabbedPage.BarSelectedItemColor="#ffffff"

Now in ios I set the selected color by adding this line in AppDelegate.cs

 UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(255, 255, 255);

But how can I adjust the color of unselected icon and text color in ios? Should I use any custom render?


Solution

  • In the latest 4.0 pre-release, there are two new properties working for both iOS and Android:

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

    Pull request here: https://github.com/xamarin/Xamarin.Forms/pull/4899

    For older versions, you have to use a custom renderer. For example this is the code for getting white color when unselected:

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

    Usually i use this code in the ViewWillLayoutSubviews override when doing other stuff like micromanaging tabbar height, background image, ecc...

        public override void ViewWillLayoutSubviews()
        {
            base.ViewWillLayoutSubviews();
    
            TabBar.UnselectedItemTintColor = UIColor.FromRGBA(255, 255, 255, 255);
    
            //doing other customization stuff here
    
        }