Ios 触发UITableViewRowAction时如何显示图像?

Ios 触发UITableViewRowAction时如何显示图像?,ios,swift,uitableview,Ios,Swift,Uitableview,我试图自定义删除选项有红色背景和垃圾图标的位置。到目前为止,与我收集和实现的内容不同,我在背景中有一个重复的图像,不知道如何将其变为红色或仅显示一个垃圾桶图像 func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let title = " " let deleteActi

我试图自定义删除选项有红色背景和垃圾图标的位置。到目前为止,与我收集和实现的内容不同,我在背景中有一个重复的图像,不知道如何将其变为红色或仅显示一个垃圾桶图像

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]
    }

我可以看出我很接近,但不确定如何将颜色和我所拥有的东西组合在一起,以显示如下图所示的东西


我认为是时候升级到这些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])
}

简单:不要使用
图案图像
。好吧,这是公平的,我没有在问题中声明我知道图案图像不起作用,但这是我得到的壁橱。DeleteAction没有背景图像属性,因此我不知所措