2016-02-01 48 views
0

我的應用程序中有幾個按鈕是利用圖片的圖片。在UITableViewCell中刪除UIButton上的imageView tint

對於在Interface Builder中設置的按鈕,我在屬性檢查器中設置圖像。如我所願,它顯示而沒有色調。我檢查了用於在界面生成器中設置圖像的方法是UIButton setImage:forState:

現在,如果我嘗試在UITableViewController中設置cellForRowAtIndexPath中的按鈕圖像,則圖像上會有一個色調。

// This puts a tint over the button 
customCell.myButton.setImage(buttonImage, forState: .Normal) 

作爲一種變通方法,我扔了一個UIImageView後面的按鈕,但是當我動畫按鈕ImageView的不動,我覺得很煩。

我也試過這樣:

// This results in a blank image on the button 
customCell.myButton.imageView?.contentMode = .ScaleAspectFit 
customCell.myButton.imageView?.image = buttonImage 

如果任何人有意見回覆:我做錯了,我歡迎您的加入。

回答

0

原來imageWithRenderingMode解決了這個問題。

創建並返回具有指定呈現模式的新圖像對象。 具有指定呈現模式的新圖像對象。

我需要使用AlwaysOriginal情況:

總是吸引原始圖像,而不把它當作一個模板。

let buttonImage = UIImage(named: buttonImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)