【问题标题】:Background color for UISearchController in UITableViewUITableView 中 UISearchController 的背景颜色
【发布时间】:2015-07-16 19:55:26
【问题描述】:

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

tableView.tableHeaderView = searchController.searchBar

我尝试了各种我能想到的方式来改变这个背景颜色:

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

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

【问题讨论】:

  • searchController.view.backgroundColor = UIColor.redColor() ?
  • 我实际上并不希望它是红色的,只是检查什么有效。这些都没有改变深灰色的背景颜色。
  • 试试这个可能会有帮助 self.tableView.contentOffset = CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height)

标签: ios swift uitableview uisearchcontroller


【解决方案1】:

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

    self.tableView.backgroundView = [UIView new];

看起来不合逻辑,但效果很好:)

【讨论】:

    【解决方案2】:

    Cameron E 在 Swift 中的正确答案:

    tableView.backgroundView = UIView()

    请注意,self.tableView.backgroundView = nil不起作用

    【讨论】:

      【解决方案3】:

      试试这个:

      [searchController.searchBar setBarTintColor:[UIColor blackColor]];
      [searchController.searchBar setTintColor:[UIColor whiteColor]];
      

      希望这会有所帮助。

      【讨论】:

      • 这正是我想要的。
      【解决方案4】:

      只需设置一个空视图作为 UITableView 的背景视图

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

      【讨论】:

        【解决方案5】:

        尝试改变颜色

        self.navigationController?.navigationBar = UIColor(red: 1, green: 1, blue: 1, alpha: 1)

        【讨论】:

          猜你喜欢
          • 2011-10-07
          • 1970-01-01
          • 1970-01-01
          • 2014-09-04
          • 2015-11-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-09-12
          相关资源
          最近更新 更多