如何调整UITableViewRowAction的大小以适应自定义大小的tableViewCell? - 斯威夫特3

问题描述 投票:0回答:2

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

Here's what it looks like这是我的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的大小以适应细胞的模具?

swift uitableview resize xcode8 uitableviewrowaction
2个回答
0
投票

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

我确实计划在SwipeTableViewCellDelegate上添加一些方法,这些方法会在显示之前暴露每个UIButton,并且当刷卡继续发生时。我想这会给你足够的灵活性来实现你的布局。

在此期间,这对你自己的叉子来说不应该太难。具体来说,看看SwipeTableViewCell方法中的configureActionView。它创建了SwipeActionsView,它具有buttons属性,包含滑动UIButton子类。您只需将这些内容公开给您的应用即可。


0
投票

如果有人在2019年仍在寻找解决方案,您可以使用不可见的unicode字符来设置宽度。

UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"\u2060\t\t\t\u2060" handler: [self handler]];
© www.soinside.com 2019 - 2024. All rights reserved.