我想将tableViewCell中标签的背景颜色设置为不透明,但我需要苹果提供的uiTableViewCell的默认背景颜色。
那么我该如何获取这个背景颜色或者它是什么颜色?
谢谢。
那么我该如何获取这个背景颜色或者它是什么颜色?
谢谢。
要重置已回收(出队)的UITableViewCell的颜色,这个方法在iOS 5、6和7中都可行:
cell.backgroundColor = nil;
正如其他人在这里建议的那样,我记录了新创建单元格的该属性值。我看到了null
。这让我想到将该属性设置为nil。在所有三个iOS版本中似乎都有效。
我模糊地记得,在UITableView和UITableViewCell中,iOS已经彻底改变了默认颜色设置的方式。在某些版本中,会选择父容器的颜色。在某些版本中,该默认颜色是灰白色的,但随着时间的推移而改变。在iOS 7中,无论父级如何,都会应用白色。注意:不要引用我在本段落中说的话;如果你关心的话,请查找相关资料。重点是,告诉你设置特定颜色的答案是错误的建议。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
谢谢!
NSLog(@"cell background color is %@", cell.backgroundColor);
或单元格的contentView
NSLog(@"cell contentView's background color is %@", cell.contentView.backgroundColor);
你也可以直接设置标签的颜色:
label.backgroundColor = cell.contentView.backgroundColor;
- (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
属性,其中包含真实可见颜色。