0

I'm having trouble setting the tabbar.unselectedItemTintColor. There is some weird conflict when I try to set both the unselectedItemTintColor and the scrollEdgeAppearance.

I can run this code and things work as expected:


UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
tabBarController.delegate = self;
tabBar.translucent = NO;

UITabBar.appearance.shadowImage = [self colorForTabBar:[UIColor darkGrayColor]]; //this is the color of the seperator line at the top.
UITabBar.appearance.unselectedItemTintColor = [UIColor purpleColor];
UIColor *tintColor =  [UIColor greenColor];

tabBar.barTintColor =  tintColor;
tabBar.backgroundImage = [self colorForTabBar:tintColor];

The unselected items are purple, and the background is green. The problem is that if I scroll down to the bottom of my view controller then the scrollEdgeAppearance is shown instead of the default, and the green color goes transparent, and my shadowImage disappears. To combat this, I have tried setting:

if (@available(iOS 15.0, *)) {
    tabBar.scrollEdgeAppearance = tabBar.standardAppearance;
}

And that makes everything turn gray! Even the standard default appearance turns gray.

I have played around with trying set all the appearance parameters like this:

if (@available(iOS 15.0, *)) {
    UITabBarAppearance *appearance = [UITabBarAppearance new];
    [appearance configureWithOpaqueBackground];
    appearance.backgroundColor = [UIColor greenColor];
    appearance.shadowImage = [self colorForTabBar:[UIColor darkGrayColor]]; //this is the color of the seperator line at the top.

    tabBar.tintColor = [UIColor redColor];
    tabBar.unselectedItemTintColor = [UIColor purpleColor];
    
    tabBar.standardAppearance = appearance;
    tabBar.scrollEdgeAppearance = appearance;
}

And that almost works except the tabBar.unselectedItemTintColor isn't working, and all my icons are gray instead of purple.

Chase Roberts
  • 9,082
  • 13
  • 73
  • 131

1 Answers1

0

I have been struggling with this same issue. Try adding this after the "appearance.shadowImage =" line:

appearance.stackedLayoutAppearance.normal.titleTextAttributes = 
@{ NSForegroundColorAttributeName : [UIColor purpleColor] };
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
S. Gano
  • 1
  • 2