[英]Change UIImageView color like UILabel's highlighted property when row is selected?
是的,可以使用突出顯示的圖像設置UIImageView顏色。 它有兩種類型的圖像屬性。 正常和突出顯示的圖像。
接口文件(storyboard / XIB)中的屬性檢查器中提供了此選項。
另一個選項可用於矢量圖像,您可以在其中為圖像資源的模板類型設置tintColor。
Swift 3您還可以以編程方式設置這兩個屬性。
let imageView = UIImageView(<set your initialiser>)
imageView.image = //Your normal image
imageView.highlightedImage = //You highligted image
根據您的tableview行選擇狀態,將圖像狀態從正常更改為突出顯示,反之亦然。 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.