在尝试编辑UITableViewCell的宽度时,部分单元格边界保留在屏幕上

时间:2013-12-18 07:55:44

标签: ios objective-c uitableview

我有一个UITableView分组样式和UITableViewCell,我需要更宽一些。所以,我将UITableViewCell子类化并实现了一个方法:

- (void) layoutSubviews
{
    [super layoutSubviews];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && !IS_OS_7_OR_LATER) {
        CGRect frame = self.frame;
        frame.origin.x -= 10;
        frame.size.width += 20;
        self.frame = frame;
    }
}

现在有一个问题 - 我的手机看起来像这样:

enter image description here

并使用颜色图层:

enter image description here

在单元格的顶部,在调整大小之前,前一个单元格的边界有一部分..这可以在第二个屏幕上清楚地看到。你能帮我解决这个边界的问题吗?

1 个答案:

答案 0 :(得分:0)

UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
backgroundView.backgroundColor =  [UIColor colorWithRed:240 green:240 blue:240 alpha:1];
cell.backgroundView = backgroundView;

试一试。