不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0) [英] Different cell bg color depending on iOS version (4.0 to 5.0)

查看:14
本文介绍了不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的分组 UITableViewCell,上面有几个 UILabel.由于 UITableViewCell 的背景颜色曾经是纯白色,它与 UILabel 的默认背景颜色匹配,因此 UILabel 框不可见..

I have a custom grouped UITableViewCell, with a couple of UILabels on it. Since the UITableViewCell background color used to be pure white, it matched the UILabels' default background color, so the UILabel box wasn't visible..

更新到 iOS 5.0 后,我注意到现在分组 UITableViewCells 的默认背景颜色是更灰白色(实际上是 #f7f7f7),因此 UILabels 的框架以丑陋的方式可见..

After updating to iOS 5.0, I notice that now the default background color for grouped UITableViewCells is a more greyish white (actually #f7f7f7), and as a consequence the UILabels' frame is visible in an ugly way..

那么,当需要在不同 iOS 版本之间变化时,设置 UILabel 的背景颜色的最佳方法是什么?我知道我可以使用 opaque = NO 和 [UIColor clearColor],但出于性能原因,我更喜欢绘制 UILabel 的背景.

So, what is the best way to set the UILabels' background color when it needs to vary between different iOS versions? I know I could use opaque = NO and [UIColor clearColor], but I would prefer to paint the UILabels' background for performance reasons.

推荐答案

在委托方法 tableView:willDisplayCell: 中,UITableViewCell 将背景颜色设置为白色或者,在 iOS 5 中,为灰色.

In the delegate method tableView:willDisplayCell:, the UITableViewCell will have the background colour set to white or, in iOS 5, greyish.

您可以更改所有子视图的所有 backgroundColor.

You can change all your the backgroundColor of all your subviews.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    for (UIView* view in cell.contentView.subviews) {
        view.backgroundColor = cell.backgroundColor;
    }
}

这篇关于不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆