UITableViewCell swipe action

694 views Asked by At

I am creating UITableView with swipe action. I have read many articles. I can do edit and delete action in the TableView. But could not create a design like i posted here. I need increase decrease button action.

Increase and decrease buttons with quantity

I have given small piece of sample code below.

   func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
   {

        let accept = UIContextualAction(style: .normal, title: "accept") { (action, view, nil) in
        print("accepted")
        }
        accept.backgroundColor = .lightGray
        accept.image = UIImage(named: "edit")
        return UISwipeActionsConfiguration(actions: [accept])
    }

Help me to achieve this. Thanks in advance.

1

There are 1 answers

1
Muhammad Hasan Irshad On

Try this method, hope it helps a bit..

func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  let increaseAction = UIContextualAction(style: .normal, title: "Increase") { (action, view, completion) in
    // Perform your addition here..
      completion(true)
  }

  let decreaseAction = UIContextualAction(style: .normal, title: "Decrease") { (action, view, completion) in
    // Perform your subtraction here..
    completion(true)
  }

  // set images to buttons..
  increaseAction.image = UIImage(named: "plusImage.png")
  decreaseAction.image = UIImage(named: "minusImage.png")

  // Just incase if want to change the backgroundColor..
  increaseAction.backgroundColor = UIColor.red
  decreaseAction.backgroundColor = UIColor.green

  return UISwipeActionsConfiguration(actions: [increaseAction, decreaseAction])
}