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

后端 未结 15 2019
慢半拍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:23

    Use the appearance proxy:

    id barButtonAppearanceInSearchBar = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
    
    [barButtonAppearanceInSearchBar setBackgroundImage:grayBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [barButtonAppearanceInSearchBar setTitleTextAttributes:@{
                                          NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:20],
                                     NSForegroundColorAttributeName : [UIColor blackColor]
         } forState:UIControlStateNormal];
    [barButtonAppearanceInSearchBar setTitle:@"X"];
    

提交回复
热议问题