gpt4 book ai didi

ios - 如何为 TableView 中的 UIContextualAction 提供自定义宽度(滑动)

转载 作者:行者123 更新时间:2023-11-30 11:54:28 26 4
gpt4 key购买 nike

我有一个简单的 TableView :

enter image description here

目前,这是我使用 UIContextualAction 向左滑动时所得到的:

enter image description here

我当前的代码:

override func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let editAction = UIContextualAction(style: .normal, title: "Modifier", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("OK, marked as Closed")
success(true)
})
editAction.image = #imageLiteral(resourceName: "leftView")
//editAction.backgroundColor = .black

let configuration = UISwipeActionsConfiguration(actions: [editAction])
//configuration.performsFirstActionWithFullSwipe = false
return configuration
}

这就是我想要的:

enter image description here

正如您所看到的,滑动按钮一直移动到单元格的中间。请问我该怎么做?

最佳答案

在 iOS11 中,tableviewcell 滑动似乎只能接受特定尺寸的图像或仅接受文本。

另一个选项是向桌面 View 添加手势。

或者向 tableviewcell 添加平移手势,首先在自定义单元格中创建一个 View ,然后在单元格中的该 View 上使用 UIPanGestureRecognizer。将需要的按钮添加到自定义单元格中,当您在自定义单元格中滑动 View 时,自定义单元格中的按钮将可见。

关于ios - 如何为 TableView 中的 UIContextualAction 提供自定义宽度(滑动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47981247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com