leedream
leedream

Reputation: 559

change the name of the searchBar cancel button IOS 7

I'm having trouble changing the text of the searchbar cancel button.

See my code:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    [_srBar setShowsCancelButton:YES animated:YES];
    UIButton *cancelButton = nil;
    for (UIView *subView in searchBar.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UIButton")]) {
            cancelButton = (UIButton*)subView;
        }
    }
    [cancelButton setTitle:@"Annuller" forState:UIControlStateNormal]; 
}

Also I already tried other options

iOS Change the title of cancel button in UISearchBar iOS - Customizing Cancel button of UISearchBar

In this example my code does not call the method

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

my scenery

#import <UIKit/UIKit.h>

@interface favorito : UIViewController<UISearchControllerDelegate, UISearchDisplayDelegate, UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>

@end

Upvotes: 0

Views: 322

Answers (1)

Mubin Mall
Mubin Mall

Reputation: 546

id barButtonAppearanceInSearchBar = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];

[barButtonAppearanceInSearchBar setBackgroundImage:grayBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barButtonAppearanceInSearchBar setTitleTextAttributes:@{
                                      UITextAttributeFont : [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:20],
                                 UITextAttributeTextColor : [UIColor blackColor]
     } forState:UIControlStateNormal];
[barButtonAppearanceInSearchBar setTitle:@"X"];

Upvotes: 1

Related Questions