繁体   English   中英

带附件的UITableViewCell

[英]UITableViewCell with accessory

我有一个使用UITableView的应用程序。 每个细胞都有配件。 但我不能设置backgroundColor ti这个单元格。

在此输入图像描述

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

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

但只有contentView工作。 我该怎么做? 日Thnx

第二种方式cell.backgroundView.backgroundColor = [UIColor redColor]; 没错。 不幸的是,在你创建一个后,没有backgroundView。 您必须创建一个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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM