UICollectionViewCell -- 使 selectedBackgroundView 大于单元格本身



我正在尝试找出一种方法来使我的单元格的选定背景视图大于单元格本身。

我的以下方法旨在使选定的背景视图: 单元格的超视图宽度(屏幕的整个宽度(X单元格的高度

UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.superview.frame), CGRectGetHeight(cell.frame))];
bg.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = bg;

选择此单元格时,背景颜色仅在单元格的限制内延伸(不超过超视图的高度(

如何最好地完成使选定的背景视图大于单元格?我在这里采取了完全错误的方法吗?

正如我测试的那样,selectedBackgroundView的框架是恒定的,你的bg的宽度变化不起作用。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath];
CGRect f = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height);
f.size.height += 20;
f.origin.y -= 10;
UIView *bg = [[UIView alloc] initWithFrame: f];
bg.backgroundColor = [UIColor redColor];
[cell.contentView addSubview: bg];
cell.contentView.clipsToBounds = false;
}

相关内容

最新更新