ios - 选择行时更改 UIImageView 颜色,如 UILabel 的突出显示属性?

标签 ios swift xcode uitableview uiimageview

UITableViewCell 被选中时,UILabelhighlighted 属性会改变标签的文本颜色。是否可以为 UIImageView 做类似的事情?

"Highlighted" property for a label

最佳答案

是的,可以设置 UIImageView 颜色,使用突出显示的图像。它有两种类型的图像属性。正常和突出显示的图像。
此选项在接口(interface)文件( Storyboard/XIB)的属性检查器中可用。
另一个选项可用于矢量图像,您可以在其中为图像资源的模板类型设置 tintColor。

swift 3 您还可以通过编程方式设置这两个属性。

let imageView = UIImageView(<set your initialiser>)
imageView.image = //Your normal image
imageView.highlightedImage = //You highligted image

根据您的表格 View 行选择状态,将图像状态从正常更改为突出显示,反之亦然。 imageView.isHighlighted = true/false

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
   imageView.isHighlighted = true
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    imageView.isHighlighted = false
}


enter image description here

关于ios - 选择行时更改 UIImageView 颜色,如 UILabel 的突出显示属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42531649/

相关文章:

objective-c - 如何显示基于 UIWindow 的暗色背景,如 UIAlertView?

ios - 卸载应用程序后存储数据

ios - UITableView 页脚、 Storyboard和 Xcode 6 的自动布局问题

ios - 如何刷新 xib View ?

objective-c - Xcode/Cocoapods 为什么我不能从 Pod 实现 Swift 协议(protocol)?

ios - 在 CALayer 上缩放图像?

ios - objective-C : Weak attritube don't work as expected

ios - 在 iOS : symbol(s) not found collect2: ld 中导入 zlib 时出错

ios - 程序化导航后退按钮未显示

swift - 从 UICollectionViewCell 中点击按钮时如何引用 UITableViewCell?