我试图增加一个子视图一个UITableViewCell和我是从需求工作,这个特定的子视图(图像)需要比实际的UITableViewCell更大,从而部分地重叠它的兄弟姐妹的设计

因此,我建立了我的表格单元格,生成的我的形象和其添加到单元格的内容查看:

// rowHeight for the UITableView is 45.0f

UIImage *image = [self createCellThumbnail: someImage];
UIImageView *thumbView = [[UIImageView alloc] initWithFrame: CGRectMake(150, -5, 55,55)];
thumbView.transform = CGAffineTransformMakeRotation(0.1f);
thumbView.image = image;

cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;

[cell.contentView addSubview: thumbView];

虽然图像将“溢出”到它下面的细胞中,图像的顶部总是限幅,如下所示:

“IMG”

有谁知道,如果我想要做的是能与目前的做法?

或者我应该想出一个办法,所有的细胞被吸引后,这些图像绘制到UITableView的(这是一个非滚动的tableview,因此,将工作和是相当容易)。

<强>更新

也曾尝试加入以下,没有效果:

cell.opaque = NO;
cell.contentView.opaque = NO;

cell.clearsContextBeforeDrawing = NO;
cell.contentView.clearsContextBeforeDrawing = NO;

cell.clipsToBounds = NO;    
cell.contentView.clipsToBounds = NO;
有帮助吗?

解决方案

我似乎的tableView呈现其细胞从底部到顶部,从而上述一个小区重叠的细胞一个小区。为了避免这种情况,你必须将所有细胞backgroundColor+[UIColor clearColor],这样你不会的的那些重叠的问题。

但设置backgroundColor-tableView:cellForRowAtIndexPath:清除没有任何意义。 UIKit中做了很多与它的前绘制细胞的东西,所以它复位电池的backgroundColor属性。

我们需要做的是设置在后面的状态backgroundColor什么。幸运的是这其中-[UITableViewDelegate tableView:willDisplayCell:forRowAtIndexPath:]我们可以实现这样的:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor clearColor];
}

现在我们设置backgroundColor之前的单元绘制的事实证明这是工作。

其他提示

<强>更新

因此,我已经做了一些更多的试验和下面的溶液仍然工作,而无需将所述小区设置到透明的背景下,这涉及到移动覆盖小区的z顺序。这适用于突出,和另一小区的选择(通过相关的回调),如果两个单元格的背景是不同的颜色。解决方法如下(可以忽略didHighlightdidSelect方法,如果他们不这样做此事给你):

(注意,“覆盖行”是其内容,我们正在努力保持可见,在我的情况下,其含量略有进入上面行,这是修剪它的人)

-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == ROW_ABOVE_COVERED_ROW)
    {
        NSIndexPath * rowbelow = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:rowbelow];
        [cell.superview bringSubviewToFront:cell];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == ROW_ABOVE_COVERED_ROW)
    {
        NSIndexPath * rowbelow = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:rowbelow];
        [cell.superview bringSubviewToFront:cell];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 && indexPath.row == COVERED_ROW)
    {
        [cell.superview bringSubviewToFront:cell];
        cell.contentView.superview.clipsToBounds = NO;
    }
}

请注意:你也可以设置你的内容的背景颜色清除,否则会采取你的其余部分将bgcolor,所以当你设法让你的内容覆盖小区的前面,它会采取的背景颜色与它留在其他小区中的讨厌的块(在我的情况下我的唯一的内容是detailTextLabeltextLabel):

// in cellForRowAtIndexPath:
[cell setBackgroundColor:[UIColor redColor]]; //using red for debug
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];

我希望这有助于任何人试图这...

<强> ORIGINAL:

有关我的解决办法是使用:

self.contentView.superview.clipsToBounds = NO;

我的细胞已经是透明的,但我的内容仍然得到修剪。在我来说,我是用其移动它的内容在layoutSubviews自定义单元格。所以layoutSubviews用于我的自定义单元格卷绕如下:

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.contentView.frame = CGRectOffset(self.contentView.frame, 0, -11);
    self.contentView.superview.clipsToBounds = NO;
}

我不知道,如果上面的单元为不透明,或这会工作,如果细胞突出按下时,这是否会掩盖我的内容。

然而,我的没有需要使细胞再次透明的viewWillDisplayCell回调方法 - 在正常cellForRowAtIndexPath这样做就足够了。

我有这个问题,我确信我的自定义tableviewcell的主要背景有剪辑子视图检查,它解决了这个问题。这是从虽然厦门国际银行加载自定义的tableview细胞。不完全一样,但类似的情况。

我其实只是昨天相反,我创造了一个自定义的表格单元格,由于某种原因,我得到了,我不希望有一个溢出。我的解决办法是将以下代码添加到我的视图控制器类:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{  
    return 175;
}

当它相匹配的表格单元格的高度没有重叠;当它太小有重叠。提醒你,虽然,我得到了非常quicky品行,所以我不相信这是一个非常好的主意,做到这一点。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top