更改搜索栏的标题和按钮大小

时间:2015-07-02 08:01:47

标签: ios objective-c uisearchbar

我想从seaarch栏更改名称的按钮,我找到了一些例子,它的工作原理是:

-(BOOL)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    UIButton *cancelButton;


    UIView *topView = self.search.subviews[0];
    for (UIView *subView in topView.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
            cancelButton = (UIButton*)subView;
        }
    }
    if (cancelButton) {
        [cancelButton setTitle:@"Annuler" forState:UIControlStateNormal];
        cancelButton.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return  YES;
}

但问题是这样的:当我开始编辑时,首先“取消”它显示出来并且在annuler出现之后。字体大小仅为取消的12。

1 个答案:

答案 0 :(得分:0)

这是我如何从搜索栏更改按钮的名称:取消到环保

 UIBarButtonItem *searchBarButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
    [searchBarButton setTitle:@"Annuler"];