Different cell bg color depending on iOS version (4.0 to 5.0)(不同的单元格背景颜色取决于 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01