【问题标题】:Customizing the default delete button and icon in UITableViewCell自定义 UITableViewCell 中的默认删除按钮和图标
【发布时间】:2017-07-03 09:48:22
【问题描述】:

我正在尝试更改默认按钮以删除表格视图中的一行(当用户向左滑动时)。 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]
}

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

谢谢! :)

【问题讨论】:

  • 是的,这是可能的。您可以再次检查该站点。该问题之前已经提出并回答了
  • 我已经看到了答案......而且我肯定做错了......我确实插入了图像......但按钮的高度仍然是相同的行...我要做的是更改按钮的高度并使其与行的高度不同...

标签: ios swift tableview tableviewcell


【解决方案1】:

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

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

【讨论】:

  • 图片大小呢?它应该更小,对吧?
  • 当您可以根据需要调整图像大小时,为什么还要编写额外的代码??
  • 你是什么意思?你的回答很好,我想知道它是怎么做的。
  • 图像更小......但这就是它的作用......prnt.sc/fr15sq我是swift的新手......我担心我在你的解释中遗漏了一些东西。 ..对不起...
  • 您的图像被填充这么多次的原因是因为它非常小。如果您只是根据单元格的大小选择更大的图像,它就不会这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-02
  • 2017-06-14
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
相关资源
最近更新 更多