flutterisbae
flutterisbae

Reputation: 345

Swift - How to vertically transform (flip) a custom UITableViewRowAction

I'm trying to implement the swipe to delete row actions in my table view, but for design purposes the table view is flipped upside down using tableView.transform = CGAffineTransform(scaleX: 1, y: -1) So my big red delete button is upside down. Is there an easy way to use cell.contentView.transform = CGAffineTransform(scaleX: 1, y: -1) on it?

I've tried to make my own swipe action using the following method

func tableView(_ tableView: UITableView,
                 editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .default,
                                      title: "Delete",
                                      handler: { (_: UITableViewRowAction, _: IndexPath) -> Void in

      })
    //Flip the text here
    return [delete]
  }

but all I see are background color and effect.

Any help? :) Much appreciated, thanks!

Upvotes: 0

Views: 332

Answers (1)

jbart12
jbart12

Reputation: 117

could you manually flip the image you want to use and assign it like this?

let deleteAction = UIContextualAction(style: .destructive, title: nil) { (_, _, completionHandler) in
    self.viewModel.deleteScan(at: indexPath.row)
    completionHandler(true)
}

deleteAction.image = UIImage(named: "upside-down-delete")
deleteAction.backgroundColor = UIColor(named: "Red800-Red500")

Upvotes: 0

Related Questions