ios7 UISearchDisplayController cancel button title 自定义取消按键标题

这里需要注意里面的那个setShowCancelButton:YES 才行 

//自定义搜索取消button title
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
    [_searchBar setShowsCancelButton:YES animated:NO];
    UIView *topView = controller.searchBar.subviews[0];
    
    for (UIView *subView in topView.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
            UIButton *cancelButton = (UIButton*)subView;
            [cancelButton setTitle:GDLocalizedString(@"cancel") forState:UIControlStateNormal];  //@"取消"
        }
    }
}


你可能感兴趣的:(ios7 UISearchDisplayController cancel button title 自定义取消按键标题)