UISearchController change 'Cancel' button title

The solution provided above could change with new iOS releases. Here is a better approach:

[searchBar setValue:@"customString" forKey:@"_cancelButtonText"];

The Swift equivalent of Burhanuddin Sunelwala answer did the trick for me!

self.searchBar.setValue("custom string", forKey: "cancelButtonText")

Thanks to Burhanuddin Sunelwala for putting me in the right direction!


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];


            NSLog(@"enableCancelButton");
            return;
        }
    }
}