objective-c - 更改 UITableViewCell 中 UITableViewCellDeleteConfirmationControl(删除按钮)的颜色

标签 objective-c ios uitableview customization

目前我正在尝试自定义 UITableViewCell 中的删除按钮。 现在我得到了类似的东西:

enter image description here

现在,我只需要更改此按钮的颜色即可,我不想更改其行为,也不想使其完全自定义。我确信这是可能的,无需创建您自己的控件来删除 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];
        }
    }
}

我该怎么做?

提前致谢!

最佳答案

UITableViewCellDeleteConfirmationControl 不是公共(public)类,您无法轻易更改其外观。

为此,我相信您必须遍历单元格的 subview 并更改其属性:

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

当然,你应该小心做这种事情,因为它相当脆弱。我建议您自己动手。

我建议 submitting a bug report向 Apple 请求能够更轻松地对其进行编辑。

关于objective-c - 更改 UITableViewCell 中 UITableViewCellDeleteConfirmationControl(删除按钮)的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12130856/

相关文章:

ios - 如何在 iOS 中使 JSON 文件可本地化?

ios - Swift UITableViewCell subview 布局更新延迟

ios - Swift - 通过导航 Controller 进行委托(delegate)

ios - UIView 可以自动获取 UIViewController 的引用吗?

iphone - 单元格 TableView 并保留

iphone - 通过协议(protocol)比较/相等两个对象

ios - 如何在 iOS 上发送短信而无需让用户同意?

iphone - 在 iPhone 上选择 tableView 单元格

iphone - 有没有办法识别在父 uitableview 中选择的单元格

ios - WatchConnectivity - 检测所有 Controller 中的应用程序上下文更改