Jared Chu
Jared Chu

Reputation: 2852

Crash app when call setUnselectedItemTintColor from UITabBar

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?

Upvotes: 2

Views: 1499

Answers (2)

iOS Lifee
iOS Lifee

Reputation: 2201

Try This

if ([[UITabBar appearance] respondsToSelector:@selector(setUnselectedItemTintColor:)]) 
    {
        [[UITabBar appearance]setUnselectedItemTintColor:AppYellowColor];
    }
    else
    {
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:AppYellowColor, NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    }

Upvotes: 0

alexburtnik
alexburtnik

Reputation: 7741

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]];
 }

Upvotes: 8

Related Questions