[英]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.