Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

centering search controller vertically iOS

I added UISearchController programmatically with code

 let searchController = UISearchController(searchResultsController: nil)

 override func viewDidLoad() {
    super.viewDidLoad()

    searchController.searchResultsUpdater = self
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Введіть значення для пошуку"
    searchController.searchBar.backgroundColor = .white
    navigationItem.searchController = searchController
    definesPresentationContext = true

}

But it seems that it is not centered vertically. How can I fix it?

enter image description here

like image 917
Ioann Will Avatar asked Oct 21 '25 11:10

Ioann Will


1 Answers

Connected SearchController to TableView instead of NavigationItem

tableView.tableHeaderView = searchController.searchBar

like image 190
Ioann Will Avatar answered Oct 23 '25 01:10

Ioann Will