gpt4 book ai didi

ios - 带有附件的 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 23:01:41 25 4
gpt4 key购买 nike

我有一个带有 UITableView 的应用程序。每个细胞都有附件。但是我无法设置此单元格的背景颜色。

enter image description here

我尝试以这种方式设置 backgrounColors:

cell.contentView.backgroundColor =[UIColor redColor];
cell.backgroundView.backgroundColor = [UIColor redColor];
cell.backgroundColor = [UIColor redColor];

但只有 contentView 有效。我该怎么做?谢谢

最佳答案

第二种方式 cell.backgroundView.backgroundColor = [UIColor redColor]; 并没有那么错。不幸的是,在您创建背景 View 之前没有背景 View 。您必须创建一个 UIView 并将其设置为单元格的背景。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
UIView *background = [[UIView alloc] initWithFrame:CGRectZero];
background.backgroundColor = [UIColor redColor];
cell.backgroundView = background;
}

关于ios - 带有附件的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9903917/

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