【问题标题】:changing UITableViewCell background改变 UITableViewCell 背景
【发布时间】:2011-08-05 03:26:06
【问题描述】:

我知道这可能已被问过数千次,我尝试通过以下方式更改 UITablewViewCell 的背景:

 cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
              cell.textLabel.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];

而我现在只有:

如何设置辅助视图背景视图颜色?

更新: 我在顶部有一个部分标题,它有一个白色背景

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:
    //in willDisplayCell
    if (indexPath.section > 0) {
        cell.backgroundColor = [UIColor blueColor];
    }
    

    【讨论】:

      【解决方案2】:

      你有点过于复杂了。您可以更改 tableview 的背景颜色,这正是您想要的。这样,您不必为每个单元格设置颜色。 :)

          self.tableView.backgroundColor = [UIColor greenColor];
      

      【讨论】:

      • 我实际上在顶部有一个部分,我不想在其中有蓝色背景..应该在屏幕截图中显示
      • 您可以将屏幕截图添加到您的帖子中吗?你说的是table view header view吗?
      【解决方案3】:

      把这个放在你的UITableViewDelegate:

      - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
          cell.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
      }
      

      【讨论】:

      • 这是否也会改变部分?
      • 它不应该改变部分颜色,你必须自己通过实现tableView:viewForHeaderInSection: 并返回你自己的视图来做到这一点。
      • 这是众多对我有用的解决方案中唯一的一个。非常感谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      相关资源
      最近更新 更多