First, Uisearchbar when used alone, set the style:
UIView *view =[mysearchbar.subviews objectatindex:0];
View.backgroundcolor =[uicolor Clearcolor];
For (UIView *backview in view.subviews) {
if ([Backview iskindofclass:nsclassfromstring (@ "Uisearchbarbackground")]) {
[Backview Removefromsuperview];
Break
}
}
Second, Uisearchbar and Uisearchdisplaycontroller when used:
// searchResultsDataSource 就是 UITableViewDataSource searchDisplayController.searchResultsDataSource = self; // searchResultsDelegate 就是 UITableViewDelegate searchDisplayController.searchResultsDelegate = self;
Don't forget this:
searchDisplayController.delegate = self;
- If you want to set the color of CancelButton:
searchBar.tintColor = [UIColor whiteColor];
- If you want to set the font for CancelButton: set it under IOS7:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{ self.searchDisplayController.searchBar.showsCancelButton = YES; UIButton *cancelButton; UIView *topView = self.searchDisplayController.searchBar.subviews[0]; for (UIView *subView in topView.subviews) { if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton"))]) { cancelButton = (UIButton*)subView;}} if (cancelButton) { //Set the new title of the cancel button [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal];}}
This is set under IOS5/6:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{ self.searchDisplayController.searchBar.showsCancelButton = YES; UIButton *cancelButton = nil; for (UIView *subView in self.searchDisplayController.searchBar.subviews) { if ([subView isKindOfClass:UIButton)]) { cancelButton = (UIButton*)subView;}} if (cancelButton){ //Set the new title of the cancel button [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal];}}
- If you want to set the background color of Uisearchbar, you can set this:
searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_bg"]];
- Set whether Uisearchdisplaycontroller is active: eg: when I click on the search list, I want Searchbar to revert to the original, that is, when the navigation bar is restored;
[searchDisplayController setActive:NO animated:YES];
ios--Common Controls--uisearchbar and Uisearchdisplaycontroller