[英]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.