1
我想爲處於未選中狀態的UITabBarItem
的標題文本和圖像設置不同的顏色。如何在UITabBarItem上設置不同的未選中圖像和文本顏色
對於選定的狀態,我可以做到這一點,像這樣:
[[UITabBar appearance] setTintColor:[UIColor purpleColor]]; // image color
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor orangeColor] } forState:UIControlStateSelected]; // text color
對於未選擇狀態,我試圖如下:
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blueColor]]; // image color
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor redColor] } forState:UIControlStateNormal]; // text color
但由於某些原因,unselectedItemTintColor
設置覆蓋任何我嘗試設置的titleTextAttributes
- 因此在上面的代碼片段中,文本和圖片都會顯示爲藍色。
我也試過直接更改titleTextAttributes
上我已經創建後UITabBarItem
(而不是使用appearance
),但這又似乎沒有任何效果。
如何獲得不同的未選顏色?可能嗎?
這肯定看起來像一個錯誤。選項可能是1)僅使用圖像,或2)使用自定義視圖的標籤欄項目,或3)自定義標籤欄控制器? – DonMag