2011-03-29 65 views
0

下面是一些我的cellForRowAtIndexPath如何设置表格单元格文本标签的背景颜色

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
... 


cell.textLabel.textAlignment = UITextAlignmentRight; 
cell.contentView.backgroundColor = [UIColor orangeColor]; 
cell.textLabel.textColor = [UIColor blueColor]; 
cell.textLabel.backgroundColor = [UIColor orangeColor]; 
cell.textLabel.text = @"text"; 


return cell; 
} 

的,因为它在Interface Builder的定义我的标签的文本颜色将变为蓝色,但是它的背景色撑!我如何定制它?

回答

0

您是否需要确保不透明度设置正确,可能是透明而不是颜色?

+0

号这表明公司在IB定义标签的背景,单元格的内容视图的不是背景的最后的地方。谢谢。 – jkally 2011-03-29 17:25:11

0

尝试

cell.textLabel.backgroundColor = [UIColor clearColor]; 

编辑:检查下面SO后,可以对你有所帮助。

UILabel Setting Transparent Background Color?

+0

同样的事情。谢谢 – jkally 2011-03-29 17:31:13

+0

@Jkally:我看不见迈克Shinoda答案.. – Jhaliya 2011-03-29 17:35:01

+0

@Jkally:检查更新的答案.. – Jhaliya 2011-03-29 17:42:58

1

OK的朋友,终于找到了。答案是覆盖willDisplayCell,由于某种原因,就是背景色设置

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.textLabel.backgroundColor = cell.contentView.backgroundColor; 
    cell.detailTextLabel.backgroundColor = cell.contentView.backgroundColor; 

} 
相关问题