从UITabBar调用setUnselectedItemTintColor时崩溃应用程序

时间:2016-11-10 07:56:27

标签: ios objective-c uitabbar

我已尝试过两条线,但这一切都导致 [UITabBar setUnselectedItemTintColor:]:无法识别的选择器发送到实例

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

有什么建议吗?

2 个答案:

答案 0 :(得分:8)

此方法仅适用于iOS 10,因此在以前的版本中会崩溃。您应该在调用之前检查方法可用性。

 if ([[UITabBar appearance] respondsToSelector:@selector(setUnselectedItemTintColor:)]) {
     [[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];
 }

答案 1 :(得分:0)

试试这个

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