① viewDidLayoutSubviews 调用方法修改滑动按钮
func customDeleteBgView (){
if #available(iOS 11.0, *) {
for subview in self.tableView.subviews where subview.isKind(of: NSClassFromString("UISwipeActionPullView")!) {
subview.backgroundColor = .white
for view in subview.subviews where view.isKind(of: NSClassFromString("UISwipeActionStandardButton")!) {
view.backgroundColor = .white
let bgView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: FITSCALE(num: 118) + 24.0))
bgView.backgroundColor = .RCColor
bgView.cornerRadius = 8
view.insertSubview(bgView, at: 0)
if let indexpath = self.editeIndexPath ,indexpath.row == 0 {
bgView.benY = 10
} else {
bgView.benY = 0
}
}
}
} else { // IOS 10以及以下
for subview in self.tableView.subviews where subview.isKind(of: NSClassFromString("UITableViewCellDeleteConfirmationView")!) {
subview.backgroundColor = .white
for view in subview.subviews where view.isKind(of: UIButton.self) {
view.backgroundColor = .white
let bgView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: FITSCALE(num: 118) + 24.0))
bgView.backgroundColor = .RCColor
bgView.cornerRadius = 8
view.insertSubview(bgView, at: 0)
if let indexpath = self.editeIndexPath ,indexpath.row == 0 {
bgView.benY = 10
} else {
bgView.benY = 0
}
}
}
}
}
② 实现TableViewDelegate
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool{
return true
}
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String?{
return "删除"
}
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
self.view.setNeedsLayout()
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
}