修改UISearchDisplayController的searchBar的cancel按钮文字为中文"取消" 设置statusBar的背景色和searchBar背景色一致

修改UISearchDisplayController的searchBar的cancel按钮文字为中文
bug.gif

]initWithFrame:CGRectMake(0, 0, VGScreenW, 20)];
//默认让imageViewStatus隐藏
_imageViewStatus.hidden = YES;
}
return _imageViewStatus;
}

  • (void)initSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64)];
    self.searchBar.backgroundImage = [UIImage imageFormColor:[UIColor clearColor] frame:CGRectMake(0, 0, VGScreenW, 64)];
    self.searchBar.barStyle = UIBarStyleDefault;
    self.searchBar.backgroundColor = [UIColor clearColor];
    [self.searchBar setBarTintColor:[UIColor colorWithWhite:0.9 alpha:0]];
    self.searchBar.translucent = YES;
    self.searchBar.delegate = self;
    self.searchBar.placeholder = TipPlaceHolder;
    self.searchBar.keyboardType = UIKeyboardTypeDefault;
    [self.mapView addSubview:self.searchBar];
    }
    //
  • (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    controller.searchBar.backgroundColor = [UIColor whiteColor];
    controller.searchBar.showsCancelButton = YES;
    self.imageViewStatus.backgroundColor = [UIColor redColor];
    self.imageViewStatus.hidden = NO;//设置imageViewstatus显示
    [self.imageViewStatus setImage:[UIImage imageNamed:@"statusBarView"]];
    [self.navigationController.navigationBar.window addSubview:self.imageViewStatus];
    [self.navigationController.navigationBar.window bringSubviewToFront:self.imageViewStatus];
    for (id searchbutton in controller.searchBar.subviews) {
    UIView *view = (UIView *)searchbutton;
    UIButton *cancelButton = (UIButton *)[view.subviews objectAtIndex:2];
    cancelButton.enabled = YES;
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];//文字
    [cancelButton setTitleColor:VGColor(255, 150, 0) forState:UIControlStateNormal];
    break;
    }
    }
    //点击取消按钮时设置imageViewStatus隐藏
  • (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.imageViewStatus.hidden =YES;
    }

你可能感兴趣的:(修改UISearchDisplayController的searchBar的cancel按钮文字为中文"取消" 设置statusBar的背景色和searchBar背景色一致)