簡體   English   中英

選擇行時,如UILabel突出顯示的屬性更改UIImageView顏色?

[英]Change UIImageView color like UILabel's highlighted property when row is selected?

當選擇UITableViewCell時, UILabelhighlighted屬性會更改標簽的文本顏色。 是否有可能為UIImageView做類似的事情?

標簽的“突出顯示”屬性

是的,可以使用突出顯示的圖像設置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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM