2016-11-10 144 views
2

我都试过线波纹管,但是这一切导致[UITabBar setUnselectedItemTintColor:]:无法识别的选择发送到实例崩溃的应用程序调用时从setUnselectedItemTintColor UITabBar

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

什么建议吗?

+2

在快速帮助选项卡,它显示 '有效性的:的iOS(10.0及更高版本),tvOS(10.0及更高版本)'。 设备中的iOS版本号是多少? – nynohu

+0

我使用了iOS 9.0设备进行测试。安,我找到了答案。 –

+1

那么你应该接受答案。 @JaredChu – Mahesh

回答

7

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

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

你有任何针对iOS 9.0设备的解决方案吗?因为你的代码不适用于它。 –

+0

@JaredChu检查旧的iOS版本的解决方案:http://stackoverflow.com/a/18433996/1689376 – alexburtnik

+1

我发现以下答案效果更好,因为外观代理是不可靠的:http://stackoverflow.com/questions/ 12504304/respondstoselector-失败换外观代理 – iOSDevil

0

尝试这个

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