我的 viewController 有一个 UISearchBar 设置为 UITableView 的标题视图。
self.tableView.tableHeaderView = self.searchBar;
在 iOS7 中,下拉到 UISearchBar 之外会显示一个不符合使用self.tableView.backgroundColor设置的深色的空白。
有没有办法摆脱空白?
我的 viewController 有一个 UISearchBar 设置为 UITableView 的标题视图。
self.tableView.tableHeaderView = self.searchBar;
在 iOS7 中,下拉到 UISearchBar 之外会显示一个不符合使用self.tableView.backgroundColor设置的深色的空白。
有没有办法摆脱空白?
我通过设置表格视图背景视图设法摆脱了这种颜色。
UIView *backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
backgroundView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = backgroundView;
由于开发人员可能会在swift时代与白色背景作斗争:
tableView.backgroundView = UIView()
经过大量试验和错误后,在将其设置为 tableHeaderView 之前将虚拟父 UIView 添加到 UISearchBar 可以防止出现空白并正确显示 tableView 的背景颜色。
UIView *parentView = [[UIView alloc] initWithFrame:searchRect];
[parentView addSubview:self.searchBar];
self.tableView.tableHeaderView = parentView;
有兴趣看看是否有更好的解决方案。
我建议在您的视图的属性检查器中启用扩展边缘的选项