2

I am trying to change the default button to delete a row in a tableview (when the user swipe left). Changing the height of the default confirmation delete button

At the same time i would like to add a custom image on the left side of the cell when entering the edit mode... [Changing the default icon when entering the edit mode to delete2

I've included in my code the:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}

 func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .destructive, title: "\u{267A}\n Delete") { (action, indexPath) in
        tableView.isEditing = false
        print("delete")
        // delete item at indexPath
    }

    return [delete]
}

is it possible to change the heigh of the confirmation delete button and add a custom image for the left icon?

Thanks! :)

shallowThought
  • 19,212
  • 9
  • 65
  • 112
Marco
  • 1,051
  • 1
  • 17
  • 40
  • 1
    Yes, it's possible. You can once check the site again. the question has already been asked and answered previously – SaiPavanParanam Jul 03 '17 at 09:57
  • Might be helpful: https://stackoverflow.com/a/35648526/1457385 – shallowThought Jul 03 '17 at 10:01
  • i've seen the answer... and definitely i'm doing smt wrong.... i did insert the image... but the height of the button is still the same of the row... what i'm trying to do is to change the height of the button and make it different from the height of the row... – Marco Jul 03 '17 at 10:03

1 Answers1

0

You need to set UIImage to backgroundColor of UITableViewRowAction.

let someAction = UITableViewRowAction(style: .Default, title: "") { value in 
        println("button did tapped!")
    }
    someAction.backgroundColor = UIColor(patternImage: UIImage(named: "myImage")!)
SaiPavanParanam
  • 416
  • 6
  • 16
  • 1
    What about the image size? It's should be smaller, right? – Mannopson Jul 03 '17 at 10:52
  • Why write extra code when you can resize the image as per your requirement?? – SaiPavanParanam Jul 03 '17 at 10:55
  • What did you mean? Your answer is excellent and I want to know how it's done. – Mannopson Jul 03 '17 at 10:59
  • the image is smaller... but here's what it does....https://prnt.sc/fr15sq I'm new to swift... and i'm afraid i'm missing something in your explanation... sorry... – Marco Jul 03 '17 at 11:14
  • the reason your image is getting populated so many times is because it is very small. If you just pick up an larger image depending upon your size of the cell, It wouldn't do so. – SaiPavanParanam Jul 03 '17 at 11:19
  • i know... but that was my question... :) sorry maybe i didn't express myself correctly... what i would like to do... is to have a the button with a different dimension compared to the cell... i would like to have the button smaller compared to the cell.... is it possibile to change just the height of the button? – Marco Jul 03 '17 at 11:24
  • @Marco what we are doing is, we are giving only the back ground to the row action. In the background instead of a color, we are giving the image. Since the background covers the entire area of the row action, you need to select a bigger image. Try for a new pic and if the colors are different, just edit them in paint. – SaiPavanParanam Jul 03 '17 at 11:25