【发布时间】:2023-03-29 18:55:01
【问题描述】:
在 iOS 6 中
[uitableview setBackgroundColor:]表格样式为UITableViewStyleGrouped时不设置颜色
而是看到默认的条纹背景。
如果样式是UITableViewStyleGrouped,我们应该如何设置表格的背景
【问题讨论】:
标签: ios6
在 iOS 6 中
[uitableview setBackgroundColor:]表格样式为UITableViewStyleGrouped时不设置颜色
而是看到默认的条纹背景。
如果样式是UITableViewStyleGrouped,我们应该如何设置表格的背景
【问题讨论】:
标签: ios6
[tableViewInstance setBackgroundView: nil];
【讨论】:
设置
[tableView setBackgroundView: nil];
在 iOS 5 中给我带来了问题,所以我使用的是:
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor yellowColor];
[tableView setBackgroundView:bview];
iOS 5 和 6 兼容!
【讨论】:
self.view.backgroundColor = TTSTYLEVAR(mainPageBackground);
self.tableView.separatorColor = TTSTYLEVAR(mainPageBackground);
self.tableView.backgroundView = nil;
为我修好了。不过,您必须小心这可能产生的其他影响。
【讨论】:
另一个简单的解决方案是在 IB 中更改 UITableView 的背景颜色。例如,我改为“白色”,它又可以工作了。
不知何故,将背景颜色保留为“默认”使得 iOS 6 不会打扰代码中的任何其他颜色设置。
【讨论】:
我会谨慎将 backgroundView 设置为 nil。以我的经验,这会导致用户在最新的 XCode 4.5 下滚动时显着降低渲染性能。这是我对这个问题的解决方案,但不会影响滚动性能:
- (void) viewWillLayoutSubviews
{
CGRect rect = [[UIScreen mainScreen] bounds];
CGRect frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
UIView *backgroundView = [[[UIView alloc] initWithFrame:frame] autorelease];
backgroundView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = backgroundView;
}
【讨论】:
在 ios 6 中,分组表视图的方法,即 backgroundColor 已被弃用,因此改为使用
[tableview setBackgroundView : nil];
【讨论】:
我知道这已被标记为已回答,但以下内容也可以:
[[UITableView appearance] setBackgroundColor:[UIColor colorWithRed:233.0/255.0 green:233.0/255.0 blue:233.0/255.0 alpha:1.0]];
[[UITableView appearance] setBackgroundView:nil];
这样您就不必在应用程序中为每个 tableView 设置。感谢作者的原始提示!
【讨论】:
将背景设置为 nil 可以完成这项工作,是的,它不会与以前的版本有任何问题。
【讨论】: