I have a problem with the UISearchBar
programmatically added inside a UIView
(on one of the child views of a TabBarController):
When the screen is first loaded, the search bar is too wide to fit fully into the view. However, when you tap inside and then tap the Cancel
button the search bar is resized so that it fits well into the UIView.
I uploaded a sample project on GitHub - the incorrect behaviour can be observed on the second tab, in the BlueViewController
class.
I've tried numerous things already, as you can probably see in the code and searched through the most popular StackOverflow answers, but none of them fixed this problem for me so far.
Here's the link to the project: https://github.com/asia-t/tabbartest
It would be great if someone could shed some light on what may be going on there.
you could implement the following method to fix the searchbar's frame:
override func viewDidLayoutSubviews() {
var searchBarFrame = searchController.searchBar.frame
searchBarFrame.size.width = vanillaSearchBar.frame.size.width
searchController.searchBar.frame = searchBarFrame
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With