主要是在 UISearchDisplayDelegate中更改;
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[_searchBar setShowsCancelButton:YES animated:NO];
if (kiOS7) {
for (UIView *subView in [[_searchBar.subviews objectAtIndex:] subviews]){
if([subView isKindOfClass:[UIButton class]]){
[(UIButton*)subView setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
else
{
for (UIView *subView in _searchBar.subviews){
if([subView isKindOfClass:[UIButton class]]){
[(UIButton*)subView setTitle:@"取消" forState:UIControlStateNormal];
}
}
} }
以上代码是ios7 下 和ios 7 之前的两个版本设置
参考:http://*.com/questions/19163723/change-cancel-button-backgroundcolor-and-text-of-uisearchbar-in-ios7