ios--Common Controls--uisearchbar and Uisearchdisplaycontroller

Source: Internet
Author: User

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:

    • About agents
 // 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.