【问题标题】:How to change UITableViewCell edit button background color?如何更改 UITableViewCell 编辑按钮背景颜色?
【发布时间】:2017-12-20 06:33:33
【问题描述】:

当 UItableview 处于编辑模式时,如果我为单元格设置自定义颜色。然后删除按钮背景颜色与我自定义单元格的背景颜色不匹配。

所以我想将删除按钮的背景颜色更改为白色 -> 黑色。

我该怎么做??

【问题讨论】:

  • 你能展示你的代码吗?
  • @IBAction func deleteCell(_ sender: Any) { if self.tableView.isEditing == true { self.tableView.isEditing = false } else { self.tableView.isEditing = true } }跨度>
  • @VishalPethani 这是我的代码
  • @usinuniverse 请用您的代码更新您的原始问题

标签: ios uitableview


【解决方案1】:

尝试以下解决方案

在您的子类UITableViewCellawakeFromNib() 方法上:

self.backgroundColor = UIColor.black

【讨论】:

    【解决方案2】:

    你不需要IBAction 来删除Cell

    尝试以下解决方案

    添加以下委托方法

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    
        let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
            // delete item at indexPath
        }
    
        let edit = UITableViewRowAction(style: .normal, title: "Edit") { (rowAction, indexPath) in 
            // edit item at indexpath
         }
    
            edit.backgroundColor = UIColor.black
            delete.backgroundColor = UIColor.black
    
        return [edit, delete]
    } 
    

    【讨论】:

    • 谢谢。但我已经知道滑动删除。我想要像我的截图一样的编辑模式。
    • 不是这样的。我想要做的是当我按下连接到 IBOUTLET 的按钮时启用 EDIT 模式,如图所示。我不想使用滑动。
    猜你喜欢
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2015-04-03
    相关资源
    最近更新 更多