【问题标题】:Wrong margin between searchbar and navigation bar搜索栏和导航栏之间的边距错误
【发布时间】:2016-11-28 14:42:08
【问题描述】:

我不知道为什么会这样。我有一个带有 UITableView 的 UIViewController,我想在其中添加一个搜索栏,以使用新的 UISearchController(Swift 3,Xcode 8.1)查询我的服务器。 我已经尝试了所有方法,例如在界面生成器中添加搜索栏,将搜索栏背景设置为 UIImage,但没有任何效果。

这是视图控制器的类准系统:

class MyViewController: UIViewController {
  var searchController = UISearchController(searchResultsController: nil)

  fileprivate func setupSearchController() {
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.barTintColor = .myColor()
    searchController.searchBar.tintColor = .white
    searchController.searchBar.backgroundColor = .myColor()
    searchController.searchBar.placeholder = "searchSomething"
    searchController.searchBar.delegate = self
    definesPresentationContext = true
    tableView.tableHeaderView = searchController.searchBar
  }
}

extension MyViewController: UISearchResultsUpdating, UISearchBarDelegate {
  // delegates methods...
}

也许这与我的设计模式有关,但我不确定 UISearchController 是否真的很新,而且我在网络上没有找到任何关于其使用的好例子。

【问题讨论】:

    标签: swift3 uisearchbar xcode8 uisearchdisplaycontroller uisearchcontroller


    【解决方案1】:

    您可以在搜索栏周围设置与导航相同的红色边框。

        searchBar.layer.borderColor = (your red color).cgColor
        searchBar.layer.borderWidth = 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 2018-02-05
      相关资源
      最近更新 更多