1

我正在寻找一个带有重叠单元格的 uitableview,如下图所示。问题是,即使我为单元格的内容视图设置了 clipsToBounds = NO,单元格假标题(例如,与前一个单元格重叠的西班牙语)也不会显示。

有谁知道如何解决这个问题?

在此处输入图像描述

这是我的代码:

- (UITableViewCell *)tableviewCellTournamentWithReuseIdentifier:(NSString *)identifier andPosition:(NSInteger)pos {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
if (pos == 0) {
    cell.clipsToBounds = NO;
    cell.contentView.clipsToBounds = NO;
    cell.frame = CGRectMake(0, 0, tournamentsTableView.frame.size.width, CELL_HEIGHT);

    UIView* row = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tournamentsTableView.frame.size.width, CELL_HEIGHT)];
    row.clipsToBounds = NO;
    row.backgroundColor = [UIColor clearColor];

    UIView* topRow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 10)];
    topRow.backgroundColor= [UIColor colorWithRed:210/255.0 green:131/255.0 blue:62/255.0 alpha:1.0];
    [row addSubview:topRow];

    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, row.frame.size.width, CELL_HEIGHT-10)];
    label.backgroundColor = [UIColor colorWithRed:63*pos/255.0 green:71*pos/255.0 blue:113/255.0 alpha:1.0];
    label.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
    label.tag = TOURNAMENT_NAME;
    label.layer.cornerRadius = 5;
    [row addSubview:label];

    [cell.contentView addSubview:row];
} else {
    cell.clipsToBounds = NO;
    cell.contentView.clipsToBounds = NO;
    cell.frame = CGRectMake(0, -10, tournamentsTableView.frame.size.width, CELL_HEIGHT);

    UIView* row = [[UIView alloc] initWithFrame:CGRectMake(0, -10, tournamentsTableView.frame.size.width, CELL_HEIGHT)];
    row.clipsToBounds = NO;
    row.backgroundColor = [UIColor clearColor];

    UIView* topRow = [[UIView alloc] initWithFrame:CGRectMake(0, -10, 100, 10)];
    topRow.backgroundColor= [UIColor colorWithRed:210/255.0 green:131/255.0 blue:62/255.0 alpha:1.0];
    [row addSubview:topRow];
    [cell bringSubviewToFront:tournamentsTableView];

    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, row.frame.size.width, CELL_HEIGHT-10)];
    label.backgroundColor = [UIColor colorWithRed:63*pos/255.0 green:71*pos/255.0 blue:113/255.0 alpha:1.0];
    label.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
    label.tag = TOURNAMENT_NAME;
    label.layer.cornerRadius = 5;
    [row addSubview:label];

    [cell.contentView addSubview:row];
}

return cell;

}

结果是: 在此处输入图像描述

4

1 回答 1

1

问题是您正试图操纵表格视图本身,这就是您遇到问题的原因。您将需要在单元格中包含“选项卡”,因为它更容易添加任意数量的插座,因为单元格本身充当单独的视图。

将您的第一行添加到单元格

UIView *topRow = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 10.0)];
topRow.backgroundColor= [UIColor colorWithRed:210/255.0 green:131/255.0 blue:62/255.0 alpha:1.0];
[cell.contentView addSubview:topRow];

然后将您的主要内容添加到单元格中,然后将其向下移动

UIView* row = [[UIView alloc] initWithFrame:CGRectMake(0.0, 10.0, tournamentsTableView.frame.size.width, CELL_HEIGHT)];
row.clipsToBounds = NO;
row.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:row];

最后摆脱单元格的背景颜色,你几乎有你的效果。

cell.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];

希望有帮助:)

于 2014-09-28T14:02:31.320 回答