如何设置表格单元格文本标签的背景颜色
问题描述:
下面是一些我的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的定义我的标签的文本颜色将变为蓝色,但是它的背景色撑!我如何定制它?
答
您是否需要确保不透明度设置正确,可能是透明而不是颜色?
答
尝试
cell.textLabel.backgroundColor = [UIColor clearColor];
编辑:检查下面SO后,可以对你有所帮助。
答
OK的朋友,终于找到了。答案是覆盖willDisplayCell,由于某种原因,就是背景色设置
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.backgroundColor = cell.contentView.backgroundColor;
cell.detailTextLabel.backgroundColor = cell.contentView.backgroundColor;
}
号这表明公司在IB定义标签的背景,单元格的内容视图的不是背景的最后的地方。谢谢。 – jkally 2011-03-29 17:25:11