改变滑动删除按钮样式
在自定义 cell 中实现如下代码:
// 改变滑动删除按钮样式
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *subView in self.subviews){
if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
CGRect cRect = subView.frame;
cRect.origin.y = 10;
cRect.size.height = self.contentView.frame.size.height - 20;
subView.frame = cRect;
// 设置部分圆角(左上与左下)
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:subView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(12,12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = subView.bounds;
maskLayer.path = maskPath.CGPath;
subView.layer.mask = maskLayer;
UIView *confirmView=(UIView *)[subView.subviews firstObject];
// 改背景颜色
confirmView.backgroundColor=[UIColor redColor];
for(UIView *sub in confirmView.subviews){
if([sub isKindOfClass:NSClassFromString(@"UIButtonLabel")]){
UILabel *deleteLabel=(UILabel *)sub;
// 改删除按钮的字体
deleteLabel.font=[UIFont boldSystemFontOfSize:15];
// 改删除按钮的文字
deleteLabel.text=@"删除";
}
}
break;
}
}
}