UISearchBar cancel 按钮设置文本

主要是在 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

http://*.com/questions/2536151/how-to-change-the-default-text-of-cancel-button-which-appears-in-the-uisearchbar

上一篇:iOS项目之“返回”手势操作相关


下一篇:【转】 ios的手势操作之UIGestureRecognizer浅析