Wrong margin between searchbar and navigation bar

336 Views Asked by At

Bug

I don't know why this happens. I've a UIViewController with a UITableView where i would like to add a search bar for querying my server using the new UISearchController (Swift 3, Xcode 8.1). I've tried everything like add the search bar in Interface builder, set search bar background to UIImage but nothing works.

This is the view controller's class barebone:

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...
}

Maybe it's something regarding my design pattern but i'm not really sure as UISearchController is really new and i haven't found any good examples on the web regarding its use.

1

There are 1 best solutions below

0
RiceAndBytes On

You can set a border around the search bar the same red color as the nav.

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