2015-04-27 35 views
3

我知道如何着色的UIImageiOS版 - Untint的UIImage

UIImage* originalImage = curiv.image; 
UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
curiv.image = imageForRendering; 
curiv.tintColor = [UIColor RedColor]; 

但如何untint原始UIImage

+0

你可以保存'UIImage'的'tintcolor',然後用紅色對它進行着色,現在你想要不要它,然後設置以前保存的tintcolor。如果情況並非如此,那麼提供更多的細節代碼。 –

+0

@VirusSavaj如何保存'UIImage'的'tintColor'?這是關於'tintColor'的代碼。 – sooon

+0

請看我的回答, –

回答

2

你可以嘗試這樣的方式

UIImage* originalImage = curiv.image; 
UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
curiv.image = imageForRendering; 
UIColor *prevTintColor = curiv.tintColor; 
//set new Tint color as Red 
curiv.tintColor = [UIColor redColor]; 


//Now if you want to set back previous color 
curiv.tintColor=prevTintColor; 

享受編碼!

+0

它的工作原理並不真正解決我的問題。因爲'UIImages'都是動態的,我可能會有幾個不加考慮。無論如何,感謝您的解決方案。 – sooon

+0

WKInterfaceImage或UIImage對象中沒有tintColor屬性。 developer.apple.com上的開發人員文檔不公開任何稱爲「tintColor」的方法,但如果我錯了,隨時糾正我。 – Ninja

+0

@simonzhu你是一半的權利,'UIImage'沒有'tintColor',但是我們已經爲'UIImageView'獲得並設置了'tintColor',在上面的問答中'curiv'是'UIImageView'的一個對象。所以我們可以爲此設置'tintColor'。你可以從Apple Developer Doc中引用。 –