0

Here is what I am doing in my AppDelegate

self.tabBarController.delegate = self;
NSDictionary *unSelectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [Utility primaryColor], NSForegroundColorAttributeName,  nil];
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIColor whiteColor], NSForegroundColorAttributeName, nil];


[[UITabBarItem appearance] setTitleTextAttributes:unSelectedAttributes
                                         forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes
                                         forState:UIControlStateSelected];

and here is my firstViewController :

[[UINavigationBar appearance] setBarTintColor:[Utility primaryColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
UITabBar * tabBar = self.tabBarController.tabBar;
UIImage *tabImage = [UIHelper makeImageWithSizeAndColor:[Utility primaryColor] : CGSizeMake(tabBar.frame.size.width/2, tabBar.frame.size.height)];
tabImage = [tabImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBar.selectionIndicatorImage = [UIHelper makeImageWithSizeAndColor:[Utility primaryColor] : CGSizeMake(tabBar.frame.size.width/tabBar.items.count, tabBar.frame.size.height)];

my tabs are changing color but the text remains white and gray. It's not changing color as per setTitleTextAttributes.

user1324887
  • 632
  • 3
  • 11
  • 32

1 Answers1

0

Try this code for changing text color.

  [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor whiteColor], UITextAttributeTextColor,
                                                           nil] forState:UIControlStateNormal];
        UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           titleHighlightedColor, UITextAttributeTextColor,
                                                           nil] forState:UIControlStateHighlighted];

Okay its deprecated .. You can try this code

   [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
                                             forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor redColor] }
                                             forState:UIControlStateSelected];

I tried your code also, thats also working fine.

  NSDictionary *unSelectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIColor blackColor], NSForegroundColorAttributeName,  nil];

    NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [UIColor redColor], NSForegroundColorAttributeName, nil];


    [[UITabBarItem appearance] setTitleTextAttributes:unSelectedAttributes
                                             forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes
                                             forState:UIControlStateSelected];
Nilesh Jha
  • 1,626
  • 19
  • 35