修改系统TableViewCell的删除按钮样式 ,对齐进行圆角设置,首先是监听到 要加入这个删除按钮的时候 进行遍历,iOS11 之后 这个删除按钮是在tableview上的,之前是在cell上面的 通过3D图 就能找到这个按钮是在哪个view上的,
在tableview的代理方法中
-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath{
[self.view setNeedsLayout];
}
此时的self.view 是Controller的
之后就是在 viewDidLayoutSubviews 中调用修改button等方法
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self configSwipeButtons];
}
因为我是削圆角 我发现 我应该处理的 是view 并不是button,但是 都是一样的 button的样式是可以修改的
if (@available(iOS 11.0, *)){
// iOS 11层级 (Xcode 9编译): UITableView -> UISwipeActionPullView
for (UIView *subview in self.couponCarTableView.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISwipeActionPullView")] && [subview.subviews count] >= 1) {
//这段代码 是修改的 view
subview.frame = CGRectMake(subview.frame.origin.x-6, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
subview.layer.cornerRadius = 10.f;
subview.layer.masksToBounds = YES;
[self.couponCarTableView sendSubviewToBack:subview];
}
}
}
else{
MYTTCouponCarTableViewCell *tableCell = [self.couponCarTableView cellForRowAtIndexPath:self.couponCarTableView.editingIndexPath];
for (UIView *subview in tableCell.subviews){
NSLog(@"subview%@-----%zd",subview,subview.subviews.count);
if ([subview isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")] && [subview.subviews count] >= 1) {
//这段代码是找到删除按钮
subview.backgroundColor = [UIColor greenColor];
UIButton *deleteButton = subview.subviews[0];
[deleteButton setBackgroundColor:[UIColor redColor]];
}
}
}