![](/img/trans.png)
[英]Change UIImageView color like UILabel's highlighted property when row is selected?
[英]Change image in UIImageView when row is selected?
該問題已經有答案更改UIImage顏色
您應該將圖像聲明為mask( .alwaysTemplate
),然后可以為任何UIColor
更改tintColor
。
使用@ NSDmitry的例子,你需要重寫setSelected(_ selected: Bool, animated: Bool)
上UITableViewCell
並設置tintColor
整個的contentView
或只是imageView
是的,可以使用突出顯示的圖像設置UIImageView顏色。 它具有兩種圖像屬性。 正常和突出顯示的圖像。
該選項在界面文件(storyboard / XIB)的屬性檢查器中可用。
矢量圖像還有另一個選項,您可以在其中為圖像資產的模板類型設置tintColor。
Swift您還可以通過編程設置兩個屬性。
let imageView = UIImageView(<set your initialiser>)
imageView.image = //Your normal image
imageView.highlightedImage = //You highligted image
在您的表格視圖行選擇狀態下,將圖像的狀態從正常更改為突出顯示,反之亦然。 imageView.isHighlighted = true / false
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
imageView.isHighlighted = true
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
imageView.isHighlighted = false
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.