2015-11-26 79 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] 
} 
相關問題