OGeek|极客世界-中国程序员成长平台

标题: ios - 自定义 UITableViewCell 中的默认删除按钮和图标 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:01
标题: ios - 自定义 UITableViewCell 中的默认删除按钮和图标

我正在尝试更改默认按钮以删除表格 View 中的一行(当用户向左滑动时)。 Changing the height of the default confirmation delete button

同时我想在进入编辑模式时在单元格左侧添加自定义图像... [更改进入编辑模式删除时的默认图标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]
}

是否可以更改确认删除按钮的高度并为左侧图标添加自定义图像?

谢谢!



Best Answer-推荐答案


您需要将 UIImage 设置为 UITableViewRowAction 的 backgroundColor。

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

关于ios - 自定义 UITableViewCell 中的默认删除按钮和图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44882478/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4