2

I've tried both line bellow but it all cause [UITabBar setUnselectedItemTintColor:]: unrecognized selector sent to instance

[self.tabBar setUnselectedItemTintColor:[UIColor blackColor]];
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];

Any suggestion?

Jared Chu
  • 2,757
  • 4
  • 27
  • 38

2 Answers2

8

This method is available on iOS 10 only, so it will crash on previous versions. You should check method availability before calling it.

 if ([[UITabBar appearance] respondsToSelector:@selector(setUnselectedItemTintColor:)]) {
     [[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];
 }
alexburtnik
  • 7,661
  • 4
  • 32
  • 70
  • Do you have any solution for iOS 9.0 devices? Because your code will not works with it. – Jared Chu Nov 10 '16 at 08:07
  • @JaredChu Check this solution for older iOS versions: http://stackoverflow.com/a/18433996/1689376 – alexburtnik Nov 10 '16 at 08:10
  • 1
    I found that the following answer works better as the appearance proxy is unreliable: http://stackoverflow.com/questions/12504304/respondstoselector-fails-for-appearance-proxy – iOSDevil Jan 04 '17 at 14:20
0

Try This

if ([[UITabBar appearance] respondsToSelector:@selector(setUnselectedItemTintColor:)]) 
    {
        [[UITabBar appearance]setUnselectedItemTintColor:AppYellowColor];
    }
    else
    {
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:AppYellowColor, NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    }
iOS Lifee
  • 2,091
  • 23
  • 32