Подтвердить что ты не робот

Как добавить изображение на кнопку удаления UITableView?

У меня есть UITableView, и я добавил к нему действия редактирования. Теперь я хочу добавить изображение над меткой кнопок delete, как:

введите описание изображения здесь

Это мой код:

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]
}

Как добавить изображение на кнопку Delete?

4b9b3361

Ответ 1

Вы можете использовать специальное изображение на цвет фона и использовать символ "\n" для выпадающего текста

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]
}