iOS:UITableViewCell的默认背景颜色是什么?

6
我想将tableViewCell中标签的背景颜色设置为不透明,但我需要苹果提供的uiTableViewCell的默认背景颜色。
那么我该如何获取这个背景颜色或者它是什么颜色?
谢谢。

当您不更改背景颜色时,它们会呈现什么颜色?这应该是默认设置。 - dasdom
那么,使用这些标签的superView属性并从该点获取backgroundColor如何? - Till
这个也不起作用。我得到了黑色的背景。这可能是因为单元格的backgroundColor为空... - Borut Tomazin
4个回答

3

要重置已回收(出队)的UITableViewCell的颜色,这个方法在iOS 5、6和7中都可行:

cell.backgroundColor = nil;

正如其他人在这里建议的那样,我记录了新创建单元格的该属性值。我看到了null。这让我想到将该属性设置为nil。在所有三个iOS版本中似乎都有效。

我模糊地记得,在UITableView和UITableViewCell中,iOS已经彻底改变了默认颜色设置的方式。在某些版本中,会选择父容器的颜色。在某些版本中,该默认颜色是灰白色的,但随着时间的推移而改变。在iOS 7中,无论父级如何,都会应用白色。注意:不要引用我在本段落中说的话;如果你关心的话,请查找相关资料。重点是,告诉你设置特定颜色的答案是错误的建议。


1

1
您可以记录单元格的背景颜色。
NSLog(@"cell background color is %@", cell.backgroundColor);

或单元格的contentView

NSLog(@"cell contentView's background color is %@", cell.contentView.backgroundColor);

你也可以直接设置标签的颜色:

label.backgroundColor = cell.contentView.backgroundColor;

两个都不起作用?我得到了这个:“单元格背景颜色为(null)”和“单元格contentView的背景颜色为(null)”。我在设备和模拟器上的cellForRowAtIndexPath方法中记录了这一点。这很奇怪。为什么会这样? - Borut Tomazin
你,我有提到过我有自定义单元格吗?“cell = [[TableViewCellController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];”。这会有问题吗? - Borut Tomazin
TableViewCellController是哪个类的子类? - jbat100
它是UITableViewCell的子类,就像应该的那样...我在uiTableView类和它的uiTableViewCell子类中都得到了null的backgroundColor。这真的很奇怪。你知道为什么会发生这种情况吗? - Borut Tomazin

1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIColor *color = [cell backgroundColor];
    NSLog(@"%@",color);

结果是

2011年11月8日17:09:20.101 test1 [5439:207] UIDeviceRGBColorSpace 1 1 1 1

这表明默认颜色为红色= 1,绿色= 1,蓝色= 1,alpha = 1。 它是白色。

请注意,UITableViewCell还具有contentView属性,其中包含真实可见颜色。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接