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 に答える