我想向表格 View 单元格添加滑动操作,但是当我添加图像而不是背景颜色时,它会返回很多图像。
这是我正在尝试的:
func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .default, title: "") { action, index in
print("more button tapped")
}
delete.backgroundColor = UIColor(patternImage: circularIcon(with: .red, size: CGSize(width: 50, height: 50), icon: #imageLiteral(resourceName: "trash-alt"))!)
let edit = UITableViewRowAction(style: .default, title: "") { action, index in
print("favorite button tapped")
}
edit.backgroundColor = UIColor(patternImage: circularIcon(with: UIColor.appColor(.green)!, size: CGSize(width: 50, height: 50), icon: #imageLiteral(resourceName: "pen-1"))!)
return [delete, edit]
}
最佳答案
因为它是从图像创建一个图案,所以没有正确地进行宽度/高度计算,所以它只是从中创建一个图案。我打赌你可以从这里得到答案: Using buttons/images in tableView:editActionsForRowAt:
关于ios - 为什么 editActionsForRowAt 返回很多图像而不是一张图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58011479/