2014-12-22 129 views
0

我已經在應用委託設置標籤欄顏色:iOS的7/8如何設置標籤欄的文本顏色

[[UITabBar appearance] setTintColor:[UIColor redColor]]; 

它的工作完美,但我還需要單獨設置文本顏色。我希望我的圖像具有紅色色調,但文字必須是白色。

這可能嗎?

+0

http://stackoverflow.com/questions/8412010/how-to-change-the-color-of-text-in-uitabbaritem-in-ios -5 – soulshined

回答

5

改變uitabbaritem顏色使用setTitleTextAttributes我希望這段代碼可以幫助您:

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [[uicolor whitecolor] } 
     forState:UIControlStateSelected]; 
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] } 
    forState:UIControlStateNormal]; 

改變形象tintcolor:

[[UITabBar appearance] setTintColor:[UIColor redcolor]]; 
1

的答案:https://stackoverflow.com/a/18734795/860343涵蓋了大部分編輯的你可能需要爲標籤欄項目執行操作。

總之這裏是代碼:

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f], 
               NSForegroundColorAttributeName : appTintColor 
               } forState:UIControlStateSelected]; 


// doing this results in an easier to read unselected state then the default iOS 7 one 

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f], 
                NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1] 
                } forState:UIControlStateNormal]; 
相關問題