UITableView trailingSwipeActionsConfigurationForRowAt 图像和标题

Posted

技术标签:

【中文标题】UITableView trailingSwipeActionsConfigurationForRowAt 图像和标题【英文标题】:UITableView trailingSwipeActionsConfigurationForRowAt image and title 【发布时间】:2018-07-10 10:56:58 【问题描述】:

ios 11 中,我们在 UITableView trailingSwipeActionsConfigurationForRowAt 中有一个功能来获取滑动事件。但是当我尝试降低行的高度时,文本消失了,只剩下图像。

有什么办法可以同时保留吗?我的单元格高度应该是 60.0,我需要同时显示图像和标题。它适用于 84.0。 @2x 的图像尺寸为 30x30,@3x 的图像尺寸为 60x60

下面是我的代码

let contextItem = UIContextualAction(style: .normal, title: "Rename")  (contextualAction, view, boolValue) in

       //do something
    
    contextItem.image = UIImage(named: "deleteIcon")
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])

【问题讨论】:

你不能同时使用这两个,而不是使用带有文本的图像 样品见:***.com/questions/50578490/… 【参考方案1】:

iOS 11 中似乎存在一个错误,即除非表格视图单元格高度为 91 点,否则它不会同时显示图像和标题。如需更多信息,请联系https://forums.developer.apple.com/thread/86009

UIContextualAction 支持文本或图像。通过用setImage:属性设置图片,基本上在创建对象的时候去掉标题。如果您需要文本和图像,则需要创建带有嵌入文本的图像。

【讨论】:

以上是关于UITableView trailingSwipeActionsConfigurationForRowAt 图像和标题的主要内容,如果未能解决你的问题,请参考以下文章

UItableview 单元格的动态高度与 UItableview 单元格内的 UItableview

UITableView

水平 UITableView 中的垂直 UITableView

如何与重叠显示的 UITableView 交互另一个 UITableView

在 UITableView 中的 UINib 中重新加载 UITableView

iOS小技能:1. 什么是UITableView? 2. UITableView如何展示数据