UISearchBar cancel 按钮设置文本

主要是在 UISearchDisplayDelegate中更改;

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
    [_searchBar setShowsCancelButton:YES animated:NO];
    if (kiOS7) {
        for (UIView *subView in [[_searchBar.subviews objectAtIndex:0] 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://stackoverflow.com/questions/19163723/change-cancel-button-backgroundcolor-and-text-of-uisearchbar-in-ios7

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

原文地址:https://www.cnblogs.com/cocoajin/p/3412667.html