首页 > 解决方案 > 如何将 cell.accessoryType 设置为图像?

问题描述

我想将电池配件类型设置为我自己的自定义图像

let cell = tableView.cellForRow(at: indexPath)
cell?.accessoryType = UIImage(named: "heart.pdf")

我将如何在 Swift 中做到这一点?

问候

标签: iosswift

解决方案


您可以在表格视图单元格的附件视图的帮助下添加自己的图像,如下所示。

let cell = tableView.cellForRow(at: indexPath)    
let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
imgView.image = UIImage(named: "{your image name}")!
cell.accessoryView = imgView

推荐阅读