Jared Chu Jared Chu - 1 month ago 29
iOS Question

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?

Answer

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