UITableViewCell 标签 opaque=YES 单击单元格时看起来很糟糕

发布于 2024-10-29 07:22:21 字数 196 浏览 1 评论 0原文

我希望我的表格单元格能够快速加载,因此我将单元格内的所有 UILabels 设置为 opaque=YES;这很好,因为我也将背景设置为白色,看起来很正常。

当您单击单元格时,问题就出现了,因为这些标签的背景是白色的,所以在尝试突出显示单元格时,选择的蓝色颜色看起来很糟糕。有解决办法吗?将这些单元格的背景颜色设置为clearColor是否会破坏设置不透明的目的?

I want my table cells to load fast, so I am setting all my UILabels inside my cell to be opaque=YES; This is fine, because I also set the backgrounds to white and it looks normal.

The problem comes when you click the cell, since the backgrounds of those labels are white, the blue selected color looks pretty bad when trying to highlight the cell. Is there a work around for this? Would setting the background color of those cells to clearColor just defeat the purpose of setting opaque?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

家住魔仙堡 2024-11-05 07:22:21

有件事你必须考虑。首先,将标签设置为不透明绝对是获得良好滚动性能的正确方法。

正确的方法是声明 UITableViewCell 的子类,并像这样覆盖 setBackgroundColor 方法,并将背景颜色转发到单元格的每个元素:

- (void) setBackgroundColor:(UIColor *)color {
    [super setBackgroundColor:color];
    [titleLabel setBackgroundColor:color];
    [imageView setBackgroundColor:color];
    [timeLabel setBackgroundColor:color];
}

我使用它作为 XIB 的文件所有者,其中tableview 单元已定义,并将 UI 元素连接到此自定义子类中的插座。

There is something you have to consider. First, setting the labels to opaque is definitely the right way of getting good scrolling performance.

The proper way to do this is declaring a subclass of UITableViewCell and overwrite the setBackgroundColor method like this and forward the background color to each element of the cell:

- (void) setBackgroundColor:(UIColor *)color {
    [super setBackgroundColor:color];
    [titleLabel setBackgroundColor:color];
    [imageView setBackgroundColor:color];
    [timeLabel setBackgroundColor:color];
}

I used this as the file's Owner of the XIB where the tableview cell is defined and have connected the UI elements to outlets in this custom subclass.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文