在swift4中自定义滑动删除按钮

customize swipe delete button in swift4

我已经自定义了滑动删除按钮,直到 swift3 [ios 9]。
我已经在 swift3

中为 ios 9 尝试过此代码
func setSwipeDeletebutton(cell : UITableViewCell, BackView : UIView) {

    //Customize Delete button
    for subview in cell.subviews {
        subview.backgroundColor = UIColor.clear

        for sub in subview.subviews {

            if String(describing: sub).range(of: "UITableViewCellActionButton") != nil {
                sub.backgroundColor = UIColor.white

                var newframe = sub.frame
                newframe.size.height = BackView.frame.size.height
                sub.frame = newframe

                sub.SetUpView()

                for view in sub.subviews {

                    if String(describing: view).range(of: "UIButtonLabel") != nil {

                        if let label = view as? UILabel {

                            label.textColor = SharedInstance.hexStringToUIColor(hex: Color.TodayActivityColor.Type_LEAVE)

                        }
                    }
                }
            }
        }
    }
}

现在,作为 ios11 中的更改,我无法使用此代码自定义滑动删除按钮。
我尝试将图像设置为滑动删除按钮,但设置不正确,因为我还想为该删除按钮添加阴影。
谁能建议我如何使用 swift4 自定义滑动删除按钮?

您正在使用以下方式访问子视图:

String(describing: sub).range(of: "UITableViewCellActionButton")

String(describing: view).range(of: "UIButtonLabel")

苹果不建议这样做。

但是,要调试此问题,请在 table 视图行操作/抽屉打开时打开视图层次结构。

您应该会在层次结构中看到您希望更改的视图。

然后根据需要更改您的字符串:

String(describing: sub).range(of: "UISwipeActionPullView")

UISwipeActionPullView可能不是你需要的,但概念是一样的。