gpt4 book ai didi

iphone - UITableViewCell 重叠

转载 作者:行者123 更新时间:2023-11-29 13:04:59 28 4
gpt4 key购买 nike

我想创建一个带有重叠单元格的 uitableview,如下图所示。问题是,即使我为单元格的内容 View 设置 clipsToBounds = NO,单元格假标题(例如,将与前一个单元格重叠的西类牙语)也不会显示。

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

enter image description here

这是我的代码:

- (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;

结果是: enter image description here

最佳答案

问题是您正在尝试自行操作 TableView ,这就是您遇到问题的原因。您需要在单元格中包含“选项卡”,因为它更容易添加任意数量的 socket ,因为单元格本身充当单独的 View 。

将顶行添加到单元格

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];

希望对您有所帮助:)

关于iphone - UITableViewCell 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18866959/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com