EDIT: I am using Autolayout.
I have a problem filling the full width of my screen with a UISearchController's searchBar. My setup is like so :
- I have a UIViewController. Inside, I have all my elements separated. There is a UITableView displaying the results.
- Since I had trouble with the searchBar overlapping the status bar, I created a plain UIView that has constraints so that it lives under the status bar and fills the full width of the UIViewController. This is a method that I have seen numerous time here.
- Finally, I create the UISearchController and add it as a subview of "wrapperView"
Here's the result :
The blue is only to see to where the container view extends
To me, the searchBar either does not fill the container properly or it is not properly centered since the side on the left does not seem to be as wide as the other side.
Also, when the search box is active, everything is displayed fine like so:
Here is the code where I do my setup:
//Mark: - Outlets
@IBOutlet weak var wrapperView: UIView!
@IBOutlet weak var tableView: UITableView!
//Mark: - Properties
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
/*!
Sets the values of the searchController and it's behaviour
*/
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
/*!
Sets the values and behaviours of the tableView
*/
tableView.delegate = self
tableView.dataSource = self
tableView.hidden = true
definesPresentationContext = true
searchController.searchBar.sizeToFit()
searchController.searchBar.frame.size.width = self.view.frame.size.width
}
Also, my search logic works fine.