Adjust SearchBar size in Navigation Bar when Orientation changes to Landscape iOS7

StackOverflow https://stackoverflow.com/questions/23547110

  •  18-07-2023
  •  | 
  •  

Question

I'm using a Storyboard where I have a UIViewController embedded in a Navigation Controller. I have placed a SearchBar into the Navigation Controller "replacing" the TextView item with it. It works as expected in portrait.

The problem is when I rotate it to Landscape, where the Searchbar remains in the center and its height seems to be bigger than the Nav Bar.

I have tried configuring the constraints, but it hasn't been successful.

Could you help me please?

Was it helpful?

Solution 2

I fixed it adding the search bar in the title view, this way:

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[self.searchBar setPlaceholder:@"Buscar Recetas"];
[self.searchBar sizeToFit];
[self.searchBar setDelegate:self];


[self.navigationItem setTitleView:self.searchBar];

Note that I'm not using a search display controller in this case. Search Display Controller already has a property where you can set the search bar in the navigation bar, like this:

self.searchdisplaycontroller.displaysSearchBarInNavigationBar = YES;

OTHER TIPS

Set Constraints to your Search bar.. It will shows the magic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top