在UITableViewCell中更改UITableViewCellDeleteConfirmationControl(删除按钮)的颜色

Ana*_*att 4 customization objective-c uitableview ios

目前我正在尝试在UITableViewCell中自定义delte按钮.现在我有类似的东西:

在此输入图像描述

现在,我需要的只是改变这个按钮的颜色,我不想改变行为,或者让它绝对自定义.我确信这是可能的,没有创建自己的控件来删除UITableView中的行.

这是我的代码:

- (void)layoutSubviews
{
    [super layoutSubviews];

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
            UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
            deleteButtonView.backgroundColor = [UIColor greenColor];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

提前致谢!

tgt*_*tgt 5

UITableViewCellDeleteConfirmationControl不是公共类,您无法轻易更改其外观.

为了做到这一点,我相信你必须遍历单元格的子视图并更改其属性:

for (UIView *subview in self.subviews) {
    if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl") {
        // Set the background using an image.
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,你应该警惕做这种事情,因为它相当脆弱.我建议你自己滚动.

我建议 Apple 提交错误报告,要求能够更轻松地编辑它.