【问题标题】:How to set the UITableView background color programmatically in ios如何在ios中以编程方式设置UITableView背景颜色
【发布时间】:2015-11-18 09:38:05
【问题描述】:

我以编程方式创建了 UITableView。我想如下更改 UITableView 背景颜色。提前致谢

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

斯威夫特

self.tableView.backgroundColor = UIColor.redColor()

取RGB值,做需要的充分

self.tableView.backgroundColor = UIColor(red: 200.0/255.0, green: 16.0/255.0, blue: 46.0/255.0, alpha: 1.0)

目标 C

self.tableView.backgroundColor = [UIColor redColor];
self.tableView.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1.0];

【讨论】:

  • 非常感谢。请您指导我如何以编程方式设置确切的 RGB 颜色
  • 您根据颜色选择器的颜色值为 [UIColor colorWithRed:0.827f green:0.780f blue:0.824f alpha:1.00f] 。您还必须使每个单元格的背景颜色相同为了实现您发布的屏幕 .cell.backgroundColor = [UIColor colorWithRed:0.827f green:0.780f blue:0.824f alpha:1.00f];或者你可以只清除单元格的背景色
【解决方案2】:

设置tableView backgroundColor 会改变所有tableView 的颜色,但是tableView 会被cell 覆盖。所以你看不到它。如果你想看到变化,你可以设置 cell.contentView.backgroundColor。

cell.contentView.backgroundColor = [UIColor greenColor];

【讨论】:

  • 你的 RGB 是 [UIColor colorWithRed:211.0/255.0 green:200.0/255.0 blue:210.0/255.0 alpha:1.0];
【解决方案3】:

在您的代码中尝试此代码

self.YourTableName.backgroundColor = [UIColor PurpleColor];
self.YourTableName.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1.0];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleCell"];

    cell.backgroundColor = [UIColor clearColor];

    return cell;
}

【讨论】:

  • 更正 ClearColor 中的错字.. cell.backgroundColor = [UIColor clearColor];
  • 又好又容易。像那样..谢谢
猜你喜欢
  • 2018-03-17
  • 2021-10-18
  • 2023-03-26
  • 2014-06-24
  • 2014-09-04
  • 2021-05-20
  • 2015-11-20
  • 1970-01-01
  • 2011-06-13
相关资源
最近更新 更多