Wissam iOS Wissam iOS - 1 year ago 67
iOS Question

UISearchController change 'Cancel' button title

How we can change the title of cancel button in search controller?

enter image description here

Answer Source

You can change the "Cancel" Button in search bar using this-

for (UIView *view in searchBar.subviews)
    for (id subview in view.subviews)
        if ( [subview isKindOfClass:[UIButton class]] )
            [subview setEnabled:YES];
            UIButton *cancelButton = (UIButton*)subview;
            [cancelButton setTitle:@"hi" forState:UIControlStateNormal];