32

我的 viewController 有一个 UISearchBar 设置为 UITableView 的标题视图。

self.tableView.tableHeaderView = self.searchBar;

在 iOS7 中,下拉到 UISearchBar 之外会显示一个不符合使用self.tableView.backgroundColor设置的深色的空白。

在此处输入图像描述

有没有办法摆脱空白?

4

4 回答 4

45

我通过设置表格视图背景视图设法摆脱了这种颜色。

UIView *backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
backgroundView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = backgroundView;
于 2013-09-19T15:51:26.253 回答
9

时代与白色背景作斗争:

tableView.backgroundView = UIView()

于 2015-05-19T12:59:44.093 回答
4

经过大量试验和错误后,在将其设置为 tableHeaderView 之前将虚拟父 UIView 添加到 UISearchBar 可以防止出现空白并正确显示 tableView 的背景颜色。

UIView *parentView = [[UIView alloc] initWithFrame:searchRect];
[parentView addSubview:self.searchBar];
self.tableView.tableHeaderView = parentView;

有兴趣看看是否有更好的解决方案。

于 2013-09-13T09:36:23.077 回答
0

我建议在您的视图的属性检查器中启用扩展边缘的选项

于 2013-09-13T09:39:21.063 回答