Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchBar: how can I stop it resizing when clicked?

I have a UISearchBar (with UISearchDisplayController) as title view of UINavigationBar. There are also two buttons on either side of the searchbar within the navbar.

When clicking on UISearchBar, it becomes wider and covers the button on the right of it.

How can I stop it from becoming wider?

Things tried but didn't work -->

  • The widened search bar then becomes the original size if the device is rotated. So, tried calling [searchBar setNeedsLayout] in -searchBarTextDidBeginEditing
  • All different auto-resizing mask options in IB

Edit: Didn't mention, but this is on iPhone (as we can put searchbar inside toolbar in iPad..)

like image 629
s-t Avatar asked Jan 11 '12 01:01

s-t


1 Answers

Actually, taking hint from this answer if the search bar is put in UIView of desired size then this is set as title view of NavBar, it doesn't go wider !

But... Since you can't make cancel button to show/not show as you wish, I realized it's not so useful.
(As seen in this question/answer etc)

like image 150
s-t Avatar answered Sep 19 '22 12:09

s-t