在我的应用程序我有一个customViewCells表视图。余子类的UITableViewCell类,并补充说将加载异步的图像和文本我使用cell.textLabel.text = @"someThext"

有关的单元的背景色被设置可选地[UIColor darkGrayColor][UIColor whiteColor]

当我在模拟器和在电话上的小区的textLabel运行的应用程序有背景白。我想将其设置为清楚,因为我想要的细胞的背景颜色是不充分的条带,然后白色然后另一个条。

在我的自定义单元格的init方法我加了,希望白会变成红色,但没有任何效果:

[self.textLabel setBackgroundColor:[UIColor redColor]];

我也尝试:

self.textLabel.backgroundColor = [UIColor redColor];

但是,这也没有工作......如果我添加一个UILabel作为一个子视图,标签的背景颜色可以设置,但我不想这样做,因为当我旋转手机我想我的标签来自动放大。

任何想法,为什么设置cell.textLabel的背景颜色不起作用?

感谢您

有帮助吗?

解决方案 2

的问题是,设置的UIKit在-setSelected方法中的细胞的背景颜色。我有法,但没有self.textLabel.backgroundColor =的UIColor clearColor] self.detailTextLabel.backgroundColor = [的UIColor clearColor];在它,所以我加入它们,在画面中提到的问题是固定的。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.textLabel.backgroundColor = [UIColor clearColor];
    self.detailTextLabel.backgroundColor = [UIColor clearColor];
}

其他提示

如果你不想子类的UITableViewCell你可以补充一点:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     [[cell textLabel] setBackgroundColor:[UIColor clearColor]];
     [[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];
}

看起来像苹果改变了这里的东西。正是这种在做iOS4的作品:

self.textLabel.backgroundColor = [UIColor xxxColor];
self.detailTextLabel.backgroundColor = [UIColor xxxColor];

至少到该标签的背景为透明或需要的背景颜色的点。仍然无法设定的自己的背景颜色。

尼斯,这是固定的,但在如果用碱SDK 4.1和分钟开发测试有点令人惊讶的。部署3.1 iPhone经典和ipad。

要设置一个清晰的背景颜色可以使用clearColor:

    [[cell textLabel] setBackgroundColor:[UIColor clearColor]];

这是什么意思?

看到这个帖子:如何设置UITableViewCellSelectionStyle属性到一些自定义颜色?

在您的情况下只使用与白色的背景颜色一个UIView

我没有尝试,但这里有一个猜测......为了在默认情况下更快地绘制标签的不透明属性可能会设置为true。

尝试

cell.titleLabel.opaque = NO;
cell.titleLabel.backgroundColor = [UIColor clearColor];

如果不工作,要么我可能会干脆放弃了在这一点上,并创建自己的UILabel的细胞。

设置你应该做这个为textLabel的颜色: t.textColor = [的UIColor colorYouWantRGB];

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top