Change UISearchBar cancel button text in iOS 8

Wilmer picture Wilmer · Mar 11, 2015 · Viewed 29.4k times · Source

I'd like to change the text from "Cancel" to "Done" of the Cancel button inside the UISearchBar in iOS 8. I am using UISearchController. I've tried different approaches for iOS 6 and iOS 7 and they do not work. Has anybody done this?

Answer

Burhanuddin Sunelwala picture Burhanuddin Sunelwala · Mar 25, 2015

Objective-C:

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

Swift:

searchBar.setValue("customString", forKey:"_cancelButtonText")