【发布时间】:2011-12-17 04:41:57
【问题描述】:
在 iOS 5 中,分组的UITableViewCell 使用tableCellGroupedBackgroundColor 颜色而不是常规的whiteColor 颜色。因此,您的自定义单元格的背景与UITableViewCell 的背景不匹配(默认,字幕, Value1、Value2 样式单元格)。
确保在自定义 UITableViewCell 和默认 UITableViewCell(以及相关联的 UILabel 和其他元素)中使用相同背景颜色的最佳方法是什么 - w.r.t. iOS4 和 iOS5 都有吗?
注意:在编辑器中,我可以看到名为 tableCellGroupedBackgroundColor 的新颜色,但没有可用的类别/方法以编程方式获取此颜色。
编辑:
您可以使用以下技术来更改单元格上控件的背景颜色,但在自定义单元格的情况下,您如何根据操作系统(iOS 4 vs iOS 5)设置适当的背景颜色?
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (UIView* view in cell.contentView.subviews) {
view.backgroundColor = cell.backgroundColor;
}
}
最简单的解决方案(我目前实施的):
这只是确保我的所有单元格都具有白色背景,而与操作系统无关。不知何故,我不需要将白色应用于cell.contentView.subviews。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor whiteColor]];
}
【问题讨论】:
标签: ios uitableview colors ios5