2015-12-14 55 views
1

我正在使用MK吊艙(https://github.com/CosmicMind/MaterialKit)嘗試在我的佈局中放置一個fab按鈕。我使用的圖像是黑色的。但晶圓廠按鈕似乎是用默認顏色覆蓋我的圖標顏色,因爲它在最終的晶圓廠按鈕中顯示出淡淡的藍色。以下是應用了圖像的原始圖像和晶圓廠按鈕的屏幕截圖。下面是我用來定製晶圓廠按鈕的唯一兩條線(我將它們分類並製作了IBDesignable,並且我正在使用的顏色是我在UIColor擴展中定義的顏色)。MK中的圖標顏色FabButton

backgroundColor = UIColor.customBlueColor() 
setImage(UIImage(named: "wifi"), forState: .Normal) 

這裏是原來的圖標和結果的截圖:

enter image description herescreenshot

我如何保持原來的圖標的顏色?

回答

1

嘗試使用tintColor屬性來調整圖標顏色。

實施例:

let img: UIImage? = UIImage(named: "wifi") 
fabButton.setImage(img, forState: .Normal) 
fabButton.setImage(img, forState: .Highlighted) 
fabButton.tintColor = UIColor.blackColor() 

另外,爲了避免發生當按FabButton,設置圖像到.​​Highlighted,以及,。正常黑色突出顯示顏色。