Search code examples
iphoneuisearchbaruisearchbardelegate

Customized UISearchBar


I've got an app with the following class:

@interface SearchViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UISearchBar *search;

How can I customize UISearchBar? I'd like to add a segmented button to allow for search options (and/or/phrase).


Solution

  • Try this:

    search.showsScopeBar = YES;
    search.scopeButtonTitles = [NSArray arrayWithObjects:@"Button",@"Titles",@"Go",@"Here",nil];
    

    That gives you the standard segmented control for search. You can use search.selectedScopeButtonIndex to check its state.