UITableView中UISearchController的背景颜色

时间:2015-07-16 19:55:26

标签: ios swift uitableview uisearchcontroller

我将SearchController的搜索栏以编程方式插入到UITableView的tableHeaderView中。当我拉起来查看搜索栏或刷新表格时,我会看到这个奇怪的深灰色,你可以在下面的图片中看到,在复习活动指示器和搜索栏之间(即使我删除了复习器,这种背景颜色仍然存在)视图):

enter image description here

tableView.tableHeaderView = searchController.searchBar

我试过用我能想到的各种方式改变这种背景颜色:

tableView.backgroundColor = UIColor.redColor()
tableView.tableHeaderView!.backgroundColor = UIColor.redColor()
searchController.searchBar.backgroundColor = UIColor.redColor()
view.backgroundColor = UIColor.redColor()

没有任何作用。这个深灰色不是我在项目中使用的自定义颜色之一,所以我知道我没有手动设置它。一旦我拿出searchController,一切都像以前一样:深灰色被其他地方看到的浅灰色所取代。

5 个答案:

答案 0 :(得分:37)

将UITableView的backgroundView设置为一个新的无用视图:

    self.tableView.backgroundView = [UIView new];

似乎不合逻辑,但就像魅力一样:)

答案 1 :(得分:12)

Cameron E在Swift中的正确答案:

tableView.backgroundView = UIView()

请注意self.tableView.backgroundView = nil 工作。

答案 2 :(得分:9)

试试这个:

BaseComponent

希望这有帮助。

答案 3 :(得分:3)

只需将空视图设置为UITableView的backgroundview

即可
[self.tableView setBackgroundView:[[UIView alloc] initWithFrame:CGRectZero]];

答案 4 :(得分:0)

尝试更改颜色

self.navigationController?.navigationBar = UIColor(红色:1,绿色:1,蓝色:1,alpha:1)

相关问题