2015-01-05 52 views
4

我有一個UITabBar設置了並且Interface Builder和圖像突出工作正常只有當我不設置全局應用色調顏色:UITabBar着色顏色不工作的圖像

tab bar without tint color

當我設置我的應用程序使用的全局色調顏色

[[UIView appearance] setTintColor:[TAStyleKit tintColor]]; 

然後所有選項卡圖像顯示爲選定狀態。

enter image description here

只有當我點擊選項卡上,然後再返回去,他們有正確的顏色。請注意「武器」選項卡是這裏灰色:

enter image description here

我在做什麼錯?

回答

8

編輯:沒關係我以前寫的,看起來像你只需要改變以下...

[[UIView appearance] setTintColor:[TAStyleKit tintColor]]; 

要...

[[UITabBar appearance] setTintColor:[TAStyleKit tintColor]]; 

注意,你試圖更改UIView而不是UITabBar的外觀。我在一個項目中運行了它,它實現了這個訣竅。

enter image description here

enter image description here

+0

我每片只是一個形象,我確實希望像 – Jan

+0

我刪除一切要應用着色顏色我寫和寫了一個解決方案,應該完成你在找什麼。您正在設置UIView而不是UITabBar的外觀。 – timgcarlson

+0

我在UIView上設置色調,因爲我希望所有的UI元素都具有這種色調而不是藍色。 – Jan

5

這裏有可能是一個更好的,當你不能或不想刪除的基本UIView.tintColor代碼。只需將標籤欄內的UIViews上的tintColor設置爲默認的灰色。

let view = UIView.appearance() 
view.tintColor = UIColor.redColor() 

let viewsInTabBar = UIView.appearanceWhenContainedInInstancesOfClasses([UITabBar.self]) 
viewsInTabBar.tintColor = UIColor(white: 144.0/255.0, alpha: 1) // default gray for inactive items 

let tabBar = UITabBar.appearance() 
tabBar.tintColor = UIColor.redColor() // actual highlight color 

不幸的是,蘋果不使用其標準的灰度值的一個...

+0

它適用於IOS 9.3或更高版本? –