2017-07-03 131 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

相关问题