Mus*_*afa 5 colors uitableview ios ios5
在iOS 5中,分组UITableViewCell使用tableCellGroupedBackgroundColor颜色而不是常规whiteColor颜色.因此,自定义单元格的背景与UITableViewCell(默认,字幕,Value1,Value2样式单元格)的背景不匹配.
什么是确保在自定义UITableViewCell和默认UITableViewCell(以及关联UILabel和其他元素)中使用相同背景颜色的最佳方法- 同时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;
}
}
Run Code Online (Sandbox Code Playgroud)
最简单的解决方案(我当前实施):
这只是确保我的所有单元格都具有白色背景,无论操作系统如何.不知何故,我不需要应用白色cell.contentView.subviews.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor whiteColor]];
}
Run Code Online (Sandbox Code Playgroud)
这是一种快速而肮脏的方法,假设我们正在处理纯色背景,没有渐变或类似的东西。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (UIView *subview in [cell.contentView subviews]) {
subview.backgroundColor = cell.backgroundColor;
}
}
Run Code Online (Sandbox Code Playgroud)
在 iOS 5 上,它可以帮助避免难看的视线。:)
| 归档时间: |
|
| 查看次数: |
3966 次 |
| 最近记录: |