2017-07-03 109 views
2

我試圖改變默認按鈕來刪除tableview中的一行(當用戶向左滑動時)。 Changing the height of the default confirmation delete button自定義UITableViewCell中的默認刪除按鈕和圖標

同時我想進入編輯模式時,對細胞的左側添加自定義圖像... [進入編輯模式時,更改默認的圖標刪除2

我已經包括在我的代碼:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    return true 
} 

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
} 

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let delete = UITableViewRowAction(style: .destructive, title: "\u{267A}\n Delete") { (action, indexPath) in 
     tableView.isEditing = false 
     print("delete") 
     // delete item at indexPath 
    } 

    return [delete] 
} 

是有可能改變的確認的喚起注意刪除按鈕,添加自定義圖像左側的圖標?

謝謝! :)

+1

是的,這是可能的。你可以再次檢查網站。該問題已被問及以前的答案 – SaiPavanParanam

+0

可能會有所幫助:https://stackoverflow.com/a/35648526/1457385 – shallowThought

+0

我見過答案...肯定我做smt錯誤....我插入圖像...但按鈕的高度仍然是行的相同...我想要做的是改變按鈕的高度,並使其不同於行的高度.. – Marco

回答

1

您需要將UIImage設置爲UITableViewRowAction的backgroundColor。

let someAction = UITableViewRowAction(style: .Default, title: "") { value in 
     println("button did tapped!") 
    } 
    someAction.backgroundColor = UIColor(patternImage: UIImage(named: "myImage")!) 
+0

圖像大小如何?它應該更小,對嗎? – Mannopson

+0

爲什麼在按照您的要求調整圖像大小時編寫額外的代碼? – SaiPavanParanam

+0

你是什麼意思?你的回答非常好,我想知道它是如何完成的。 – Mannopson

相關問題