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:@"取消" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor colorWithRed:53.f/255.f green:114.f/255.f blue:255.f/255.f alpha:1.0] forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont fontWithName:@"Heiti SC" size:15];
}
原来还有个方法
self.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:53.f/255.f green:114.f/255.f blue:255.f/255.f alpha:1.0];
效果图