6

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..)

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
s-t
  • 385
  • 4
  • 14
  • Possible duplicate and answer: http://stackoverflow.com/questions/3006209/uisearchbar-animation-hidding-button – Collin Price Jan 31 '12 at 19:37
  • @CollinPrice Unfortunately, answer in the link you mentioned doesn't work. :( Adding [self.searchBar setFrame:CGRectMake(0.0, 0.0, 150.0, 44.0)]; for example in searchBarTextDidBeginEditing:(UISearchBar *)searchBar method did nothing... – s-t Feb 01 '12 at 02:11
  • seem to trigger with searchDisplayControllerDidBeginSearch: but it still widens a little - must be the auto-sizing of the title view. – s-t Feb 01 '12 at 02:40

1 Answers1

9

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)

Community
  • 1
  • 1
s-t
  • 385
  • 4
  • 14