2016-11-10 55 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]; 
    }