4

I constantly see, on snapchat, instagram, and pretty much every major app - UISearchBars which have a height of 44px. However, I have tried every online 'solution' and have not been able to figure this out.

Here is another thread which no one seemed to find a solution to the 'sub-issue' of it - how to make a UISearchBar's height 44px in iOS 12 and up: UISearchBar increases navigation bar height in iOS 11

Note - I have joined this community on a new account and have been building iOS applications for many years. I am asking if anyone found a solution to this or do you have to build your own custom search bar (UIView with a textfield in it, etc.)?

private var searchController = UISearchController(searchResultsController: nil)

private func setupSearchController() {

  navigationItem.searchController = searchController

  searchController.delegate = self
  searchController.searchResultsUpdater = self
  searchController.definesPresentationContext = true
  searchController.searchBar.autocorrectionType = .yes
  searchController.searchBar.searchBarStyle = .minimal
  searchController.obscuresBackgroundDuringPresentation = false
}

override func viewDidLoad() {
   super.viewDidLoad()

   setupSearchController()
}

override func viewWillAppear(_ animated: Bool) {
   super.viewWillAppear(animated)

   view.setNeedsLayout()

   navigationItem.largeTitleDisplayMode = .never
   navigationItem.hidesSearchBarWhenScrolling = true
   navigationController?.setNavigationBarHidden(false, animated: false)

}

override func viewDidAppear(_ animated: Bool) {
   super.viewDidAppear(animated)

   navigationItem.hidesSearchBarWhenScrolling = true
}

override func viewWillDisappear(_ animated: Bool) {
   super.viewWillDisappear(animated)

   navigationItem.largeTitleDisplayMode = .never
}

override func viewDidDisappear(_ animated: Bool) {
   super.viewDidDisappear(animated)

   navigationItem.hidesSearchBarWhenScrolling = false
}
Colin Cavill
  • 197
  • 7

0 Answers0