'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:
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?
Solution 1:[1]
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]
}
Solution 2:[2]
You can implement a swipeable tableviewcell to accomplish this where you can implement custom button for edit actions. There are lot of tutorials on this. Check the below one:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Aleksey Kornienko |
Solution 2 | Arun Gupta |