Changing tint color of system image in trailing swipe action

654 Views Asked by At

I'm trying to change color of trash system image but it doesn't work for some reason.

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .normal, title: nil) { (ac: UIContextualAction, view: UIView, success: (Bool) -> Void) in
        let cell = tableView.cellForRow(at: indexPath) as? HeroTableViewCell
        if let _ = cell?.nameLabel.text {
            self.deleteHeroName(index: indexPath)
        }
        success(true)
    }
    deleteAction.image = UIImage(systemName: "trash")?.withTintColor(.red)
    return UISwipeActionsConfiguration(actions: [deleteAction])
}

I need it because I'm trying to give clear background to my delete action and image color is white.

1

There are 1 best solutions below

0
zalogatomek On

For me adding rendering mode as .alwaysOriginal (note, not .alwaysTemplate as we would usually use for tinting an image) worked:

action.image = UIImage(systemName: "trash")?.withTintColor(.red, renderingMode: .alwaysOriginal)