0

UISearchController created and used like this in viewDidLoad

search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.obscuresBackgroundDuringPresentation = false
search.definesPresentationContext = true
search.searchBar.placeholder = "Search books"

navigationItem.searchController = search

I need to change horizontal position (offset, inset?) of the searchBar (search text field?) to align with title and content.

issue

I already tried to change the frame of searchBar in viewDidAppear (left pic below), but it goes back when text field becomes first responder (right pic).

frame changed in viewDidLoad frame is back when text field is first responder

Is there any working solution?

andriy_fedin
  • 175
  • 2
  • 9
  • If you use navigationItem.searchController you will get it at the default position. try navigationItem.titleView with custom view and add your search controller inside that custom view – Prashant Tukadiya Apr 06 '20 at 10:46
  • @PrashantTukadiya, thanks for your comment! It doesn't work when I try to do it though. Could you share an example, tip or an URL to a tutorial? Also I suppose this solution will remove default navigation look collapsing behaviour, which is unwanted. – andriy_fedin Apr 06 '20 at 11:50

0 Answers0