Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force scope bar below UISearchBar

I have a UISearchBar and UISearchDisplayController, everything works great but my scope selector displays beside the text field instead of below it. I know that this is the expected action when the device is in landscape, but since I have the UISearchBar in the master view of a UISplitViewController it ends up looking like this:

UISearchBar problem

Is there any way to force the scope bar to display below the text field in all interface orientations (I know that this works nicely in Mail.app on the iPad, so its possibly, but who knows if Apple decided to hide the option to do so)

like image 274
axiixc Avatar asked Apr 08 '10 20:04

axiixc


3 Answers

This is not part of the public API. Hopefully it will be added in the future. It can be accomplished using Private APIs, looking through a UIKit class dump will help you there.

Good luck!

edit: Note that using private APIs can get you rejected from the app store, as most people already know.

like image 124
logancautrell Avatar answered Nov 19 '22 07:11

logancautrell


I used the UISearchDisplayDelegate to show and hide the scope bar.

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
    [controller.searchBar setShowsScopeBar:YES];
}

-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
    [controller.searchBar setShowsScopeBar:NO];
}
like image 2
Joe Avatar answered Nov 19 '22 08:11

Joe


Don't use private APIs. Instead, follow Apple's recommendation from IOS User Interface Guidelines:

When a search bar is present, a scope bar can appear near it. The scope bar displays below the search bar, regardless of orientation, unless you use a search display controller in your code (for more information on the way this works, see UISearchDisplayController Class Reference). When you use a search display controller, the scope bar is displayed within the search bar to the right of the search field when the device is in landscape orientation (in portrait orientation, it’s below the search bar).

This worked for me using storyboards.

like image 1
Terry Westley Avatar answered Nov 19 '22 08:11

Terry Westley