我尝试自定义删除选项的红色背景和垃圾桶图标。从我收集和实施的内容到目前为止,我在背景中有一个重复的图像,不知道如何将其变为红色或只显示1个垃圾桶图像
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let title = " "
let deleteAction = UITableViewRowAction(style: .default, title: title) { (action, indexpath) in
}
let image = UIImage(named: "icon_trash")
if let im = image {
deleteAction.backgroundColor = UIColor(patternImage: im)
}
return [deleteAction]
}
我可以看到我关闭但不确定如何分割颜色以及我在一起以显示如下图所示的内容
答案 0 :(得分:2)
我认为现在是时候用图像属性
升级到这些ios 11新方法了public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
所以试试这个
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
// Call edit action
// Reset state
success(true)
})
deleteAction.image = UIImage(named: "icon_trash")
deleteAction.backgroundColor = .red
return UISwipeActionsConfiguration(actions: [deleteAction])
}