在iOS 12中,UIContextualAction并没有推断出图片的颜色。虽然它适用于iOS 13和更多版本。我尝试过图标的所有呈现模式,但仍然不起作用。
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
}
let editAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
}
deleteAction.image = UIImage(named: "trashcan")
editAction.image = UIImage(named: "cellEdit")
let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
return configuration
}


发布于 2021-02-20 09:34:13
你可以试试这个
class ImageWithoutRender: UIImage {
override func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage {
return self
}
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
}
let editAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
}
if let cgImageTrashcan = UIImage(named: "trashcan")?.cgImage {
deleteAction.image = ImageWithoutRender(cgImage: cgImageTrashcan, scale: UIScreen.main.nativeScale, orientation: .up)
}
if let cgImageCellEdit = UIImage(named: "cellEdit")?.cgImage {
editAction.image = ImageWithoutRender(cgImage: cgImageCellEdit, scale: UIScreen.main.nativeScale, orientation: .up)
}
let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
return configuration
}https://stackoverflow.com/questions/66289965
复制相似问题