How to change the default text of Cancel Button which appears in the UISearchBar +iPhone

后端 未结 15 2020
慢半拍i
慢半拍i 2020-12-01 03:04

I am developing an Application where I wanted to change the text of Search String in the SearchBar. I wanted to change the text of Cancel Button Also which appears next to t

15条回答
  •  误落风尘
    2020-12-01 03:34

    In iOS 7 if you are using UISearchBar just write this code in searchBarTextDidBeginEditing: method

    searchBar.showsCancelButton = YES;UIView* view=searchBar.subviews[0];
    for (UIView *subView in view.subviews) {
          if ([subView isKindOfClass:[UIButton class]]) {
              UIButton *cancelButton = (UIButton*)subView;
    
              [cancelButton setTitle:@"إلغاء" forState:UIControlStateNormal];
           }
    }
    

提交回复
热议问题