我自定义了滑动删除按钮,直到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)
}
}
}
}
}
}
}
现在,作为ios 11的更改,我无法使用此代码自定义滑动删除按钮。
我试图将图像设置为滑动删除按钮,但它没有正确设置,因为我还想要删除按钮的阴影。
任何人都可以建议我如何使用swift4自定义滑动删除按钮?
答案 0 :(得分:2)
您正在使用以下网址访问子视图:
String(describing: sub).range(of: "UITableViewCellActionButton")
并且
String(describing: view).range(of: "UIButtonLabel")
苹果不推荐这样做。
但是,要调试此问题,请在表视图行动作/抽屉打开时打开视图层次结构。
您应该在层次结构中看到要更改的视图。
然后根据需要更改你的字符串:
String(describing: sub).range(of: "UISwipeActionPullView")
UISwipeActionPullView
可能不是您需要的,但概念是相同的。