2015-11-26 143 views
11

我有一个UITableView,并且向它添加了编辑操作。现在,我想补充上方的删除按钮标签图像,如:如何在UITableView删除按钮上添加图像?

enter image description here

这是我的代码:

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按钮添加图像?

+0

@rmaddy但其他开发人员如何做到这一点? –

+0

也许他们正在使用第三方自定义表格视图单元类,而不是使用'UITableViewDelegate'提供的标准API。 – rmaddy

+1

提到这个问题,你会发现你的答案: http://stackoverflow.com/questions/20290766/change-the-color-of-default-red-color-delete-button-in-uitableviewcell-when- swip ---------------- http://stackoverflow.com/questions/29335104/how-add-custom-image-to-uitableview-cell-swipe-to -delete 如果你在iOS8 + –

回答

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] 
} 
相关问题