UITableViewCell背景颜色在iOS5和iOS4不同 [英] UITableViewCell background color is different in iOS5 vs iOS4

查看:213
本文介绍了UITableViewCell背景颜色在iOS5和iOS4不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分组的 UITableViewCell 使用 tableCellGroupedBackgroundColor 颜色代替常规 whiteColor UITableViewCell (默认,Subtitle,Value1,Value2样式单元格)的背景不匹配, 。



确保在自定义 UITableViewCell 中使用相同背景颜色的最佳方法是$ c> UITableViewCell (和相关 UILabel 和其他元素) - wrt iOS4和iOS5?



注意:在编辑器中,我可以看到一个新的颜色 tableCellGroupedBackgroundColor



p>您可以使用以下技术来更改单元格上的控件的背景颜色,但是在自定义单元格的情况下,如何根据操作系统(iOS 4和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]];
}


解决方案

肮脏的方式做它,假设我们处理一个坚实的背景颜色,没有渐变或任何类似的。

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



在iOS 5上,它可以帮助避免不雅观的行。 :)


The grouped UITableViewCell uses tableCellGroupedBackgroundColor color instead of regular whiteColor color, in iOS 5. As a result, the background of your custom cells doesn't match with those of UITableViewCell (Default, Subtitle, Value1, Value2 style cells).

What's the best way to make sure that same background color is used in custom UITableViewCell and default UITableViewCell (and associated UILabel and other elements) - w.r.t. both iOS4 and iOS5?

Note: In the Editor i can see a new color by the name of tableCellGroupedBackgroundColor, but there's no category/method available to get this color programmatically.

Edit:

You can use following technique to change the background color of controls on your cell, but in-case of custom cells, how can you set appropriate background color based on the OS (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;
    }
}

Easiest solution (my current implemented): This just makes sure that all my cells have white background, irrespective of the OS. Somehow, i don't need to apply white color to cell.contentView.subviews.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setBackgroundColor:[UIColor whiteColor]];
}

解决方案

Here's one quick-and-dirty way to do it, presuming we're dealing with a solid background color, no gradients or anything like that.

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

On iOS 5, it can help avoid unsightly view lines. :)

这篇关于UITableViewCell背景颜色在iOS5和iOS4不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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