1

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.

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
TayaR
  • 31
  • 4

1 Answers1

1

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)
zalogatomek
  • 666
  • 1
  • 9
  • 19