1

我有带有背景图案的自定义 UITableViewCell

使用这种方法

- (void)tableView:(UITableView *)tableView willDisplayCell:(homeCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
}

结果很好,

图片链接:链接

但是当我滑动删除时,删除按钮带有覆盖单元格内容的背景颜色

图片链接:链接

我遵循了我在stackoverflow中找到的一些解决方案,但没有一个解决我的问题

我尝试使用此代码清除删除按钮的背景颜色

- (void)tableView:(UITableView *)tableView willDisplayCell:(homeCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    // create uiview
    UIView* myBackgroundView            = [[UIView alloc] initWithFrame:CGRectZero];
    myBackgroundView.backgroundColor    = [UIColor clearColor];

    // assign the uiview
    cell.editingAccessoryView   = myBackgroundView;
    cell.backgroundView         = myBackgroundView;

    // my background patter
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"CellBG.png"]];
}

但是效果不好,整个单元格背景都是没有背景色的

图片链接:链接

如何显示没有背景颜色的删除按钮?请帮忙


我尝试过的一些解决方案: 链接1

链接 2

链接 3

4

1 回答 1

1

问题不是来自删除按钮背景,问题是当显示删除按钮时,您的 UITableViewCell 内容视图大小会减小。通过添加来自 IB 的标签,它们被添加到 contentView。

我在其他项目中所做的(我没有使用自动布局)我设置了弹簧和支柱,以便在调整 UITableView 单元格大小时调整标签大小。

于 2013-05-01T11:57:22.733 回答