如何调整UITableViewRowAction的大小以适应自定义大小的tableViewCell?(How to resize a UITableViewRowAction to fit custo

编程入门 行业动态 更新时间:2024-10-25 18:27:38
如何调整UITableViewRowAction的大小以适应自定义大小的tableViewCell?(How to resize a UITableViewRowAction to fit custom sized tableViewCell? - Swift 3)

在我的应用程序中,我将我的TableViewCell自定义为像卡片一样显示。 我也为这些单元实现了自定义的UITableViewRowActions 。 然而,这些动作看起来很奇怪,因为我添加了一个图层来使单元格看起来像一张浮动卡片。

下面是它的样子 。这里是我的cellForRowAt函数的代码。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell cell.delegate = self cell.backgroundColor = .clear cell.contentView.backgroundColor = .clear let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20)) whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9]) whiteRoundedView.layer.masksToBounds = false whiteRoundedView.layer.cornerRadius = 2.0 whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1) whiteRoundedView.layer.shadowOpacity = 0.2 cell.contentView.addSubview(whiteRoundedView) cell.contentView.sendSubview(toBack: whiteRoundedView) cell.updateCell() return cell }

和我的UITableViewRowAction函数。 预警:我正在使用这个SwipeCellKit存储库

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { if orientation == .left { guard isSwipeRightEnabled else { return nil } let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in print("complete!") } completeAction.backgroundColor = .green return [completeAction] } else { let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in print("delete") } return [deleteAction] } }

有什么办法调整UITableViewRowAction大小来适应单元格的模型吗?

In my app I customized my TableViewCell to display like a card. I also implemented custom UITableViewRowActions for those cells. However the actions look weird because I added a layer to make the cell look like a floating card.

Here's what it looks like And here's my code for my cellForRowAt function.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell cell.delegate = self cell.backgroundColor = .clear cell.contentView.backgroundColor = .clear let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20)) whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9]) whiteRoundedView.layer.masksToBounds = false whiteRoundedView.layer.cornerRadius = 2.0 whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1) whiteRoundedView.layer.shadowOpacity = 0.2 cell.contentView.addSubview(whiteRoundedView) cell.contentView.sendSubview(toBack: whiteRoundedView) cell.updateCell() return cell }

And my UITableViewRowAction function. Forewarning: I am using this SwipeCellKit repository

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { if orientation == .left { guard isSwipeRightEnabled else { return nil } let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in print("complete!") } completeAction.backgroundColor = .green return [completeAction] } else { let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in print("delete") } return [deleteAction] } }

Is there any way to resize the UITableViewRowAction to fit that mold of the cell?

最满意答案

如果不对框架进行一些更改,目前是不可能的。

我打算在SwipeTableViewCellDelegate添加一些方法,这些方法会在显示之前公开每个UIButton ,并继续发生SwipeTableViewCellDelegate 。 我想这会给你足够的灵活性来实现你的布局。

与此同时,在你自己的分支上这不应该太难。 具体来说,查看configureActionView方法中的SwipeTableViewCell 。 它创建了SwipeActionsView ,其中包含一个包含滑动UIButton子类的buttons属性。 你只需要将它们暴露给你的应用程序。

It's not currently possible without making some changes to the framework.

I do have plans to add some methods to SwipeTableViewCellDelegate which would expose each UIButton just before being displayed, and as swiping continues to occur. I imagine that would give you enough flexibility to achieve your layout.

This shouldn't be too hard to do on your own fork in the meantime. Specifically, look at SwipeTableViewCell, inside the configureActionView method. It creates the SwipeActionsView which has a buttons property containing the swipe UIButton subclass. You just need to expose those to your app.

更多推荐

本文发布于:2023-07-23 18:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小   自定义   以适应   UITableViewRowAction   tableViewCell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!