选择highlighted
时,UILabel
的UITableViewCell
属性会更改标签的文本颜色。是否可以对UIImageView
进行类似的操作?
发布于 2017-03-01 12:39:20
是的,UIImageView颜色可以设置,使用高亮显示的图像。它对图像有两种类型的属性。正常和突出显示的图像。
此选项可在接口文件(情节提要/XIB)中的属性检查器中获得。
另一个选项可用于矢量图像,您可以为图像资产的模板类型设置tintColor。
Swift 3还可以通过编程方式设置这两个属性。
let imageView = UIImageView(<set your initialiser>)
imageView.image = //Your normal image
imageView.highlightedImage = //You highligted image
在您的表视图行选择状态下,将图像状态从普通更改为高亮显示,反之亦然。imageView.isHighlighted =真/假
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
imageView.isHighlighted = true
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
imageView.isHighlighted = false
}
https://stackoverflow.com/questions/42531649
复制相似问题