本文介绍了iOS更改UISearchBar中取消按钮的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在iOS中更改取消按钮的标题。我之前一直在使用它:

I wish to change the title of the cancel button in iOS. I have been using this previously:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
  self.searchDisplayController.searchBar.showsCancelButton = YES;
  UIButton *cancelButton = nil;
  for (UIView *subView in self.searchDisplayController.searchBar.subviews) {
     if ([subView isKindOfClass:NSClassFromString(@"UIButton")]) {
         cancelButton = (UIButton*)subView;
     }
  }
  [cancelButton setTitle:@"Annuller" forState:UIControlStateNormal];
}

但它似乎不适用于iOS7。有什么建议么?

But it doesnt seem to work in iOS7. Any Suggestions?

推荐答案

只需为此代码执行此操作: -

simply do this code for it:-

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    /* when user start editing in serchbar this method will display cancel button and disable the autocorrection functionality */

    srcbar.showsCancelButton = YES;

    for (UIView *subView in searchBar.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
           UIButton *cancelButton = (UIButton*)subView;

            [cancelButton setTitle:@"hi" forState:UIControlStateNormal];
        }
    }
    srcbar.autocorrectionType = UITextAutocorrectionTypeNo;

}

不在iOS7中测试,但这在iOS6中工作正常希望这个为你工作。

Not test in iOS7 but this working fine in iOS6 hope this working for you.

输出是: -

这篇关于iOS更改UISearchBar中取消按钮的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 04:41