Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add image on UITableView delete button?

I have an UITableView and I've added edit actions to it. Now I want to add image above the delete buttons label, as:

enter image description here

This is my code:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {

    let blockAction = UITableViewRowAction(style: .Normal, title: "Block") { (rowAction:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
        //TODO: Delete the row at indexPath here
    }
    blockAction.backgroundColor = UIColor.redColor()

    return [blockAction]
}

How can I add image on my Delete button?

like image 365
Orkhan Alizade Avatar asked Nov 26 '15 15:11

Orkhan Alizade


1 Answers

You can use special image on background color and use '\n' symbol for let down text

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    let blockAction = UITableViewRowAction(style: .normal, title: "\nBlock") { (rowAction:UITableViewRowAction, indexPath:IndexPath) -> Void in
        //TODO: Delete the row at indexPath here
    }
    blockAction.backgroundColor = UIColor(patternImage: UIImage(named: "delete_background")!)

    return [blockAction]
}
like image 146
Aleksey Kornienko Avatar answered Sep 18 '22 12:09

Aleksey Kornienko