2

How can I make a tableviewcell's slide to delete look like the slide to delete for iOS notifications (fade in and don't touch edge of the screen). I will only have the delete button so I don't need multiple buttons. I would like it to delete upon a full swipe just like the notifications.

Here's a photo of the wanted result with 2 buttons (I only want 1):

iOS notification swipe to delete

The current code I have written only sets the editing style to delete. I have tried using UIContextualAction but I believe I can only set the style, background color, and/or image.

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        print("delete")
    }
}

This is what it looks like with my current code:What I currently have

  • 1
    Morning and welcome to SO! :) Remember to include some code samples within your question. – garfbradaz Jul 01 '18 at 06:21
  • Thanks! I just added my code above. I know it's not much and I haven't been able to find pretty much anything to help me. I'm just looking for ideas or solutions to ways to achieve a similar result. – Alex Arovas Jul 01 '18 at 17:41
  • https://stackoverflow.com/questions/1615469/custom-delete-button-on-editing-in-uitableview-cell – Hunaid Hassan Jul 01 '18 at 17:53
  • You are better off creating the entire UI yourself instead of trying to customise the Delete button OS provides – Hunaid Hassan Jul 01 '18 at 17:54
  • Thanks for the link. For the most part a lot of the code is meant for iOS 3-4 and one answer for iOS 7. I'm trying to convert some of their code to swift and make the necessary changes for iOS 11 but I'm still not getting far. – Alex Arovas Jul 02 '18 at 06:40

1 Answers1

0

Try adding a UIView inside the UITableViewCell, with a red background, and a label inside the UIView with the text of delete. Good Luck!

KingCoder11
  • 415
  • 4
  • 19
  • Thanks for the answer but I'm trying to get the result in the first photo not the second. I also want the clear button to be interactive by sliding over and clearing just like in the iOS Notification Center. – Alex Arovas Jul 02 '18 at 06:41