Referred here and here. No answer in first link. In the second link, though the answer is not accepted, but the link to apple developer forum gives error.
Before i
Adding these lines fixed it for me:
override func viewDidLayoutSubviews() { self.searchController.searchBar.sizeToFit() }