UISearchBar width incorrect in terrain

My search bar is a little stretched too far when you start in landscape mode. It is still a little too wide if you then rotate in portrait mode. However, this is great if you start in portrait mode and then turn it into landscape. Here is my code.

sBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; [sBar sizeToFit]; sBar.delegate = self; sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin; [self.view addSubview:sBar]; 
+4
source share
3 answers

The answer was to add a search string to the view before running the rest of the code.

 UISearchBar * tempSBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; self.sBar = tempSBar; [tempSBar release]; [self.view addSubview:sBar]; [sBar sizeToFit]; sBar.delegate = self; sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin; 
+6
source
 UIViewAutoresizingFlexibleRightMargin 

add this to sBar.autoresizingMask, I have it the same as the other 2, and there are no problems. if you are using IB, make sure the right width is there.

0
source

I know this is old and outdated, but I just had to share it. I looked high and low for a solution that would work for my business. I tried all the suggestions to no avail. Then I stumbled upon this stone

 // Update search bar frame. CGRect superviewFrame = self.searchDisplayController.searchBar.superview.frame; superviewFrame.origin.y = 0.f; self.searchDisplayController.searchBar.superview.frame = superviewFrame; 

And everything again became beautiful and sunny. Thanks, Peter. http://petersteinberger.com/blog/2013/fixing-uisearchdisplaycontroller-on-ios-7/

0
source

All Articles