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?
Objective-C:
[searchBar setValue:@"customString" forKey:@"_cancelButtonText"];
Swift:
searchBar.setValue("customString", forKey:"_cancelButtonText")
This worked for me in ios8 through ios13, did not try in ios7, but should do the trick, beware of placing this line in the early times of the app cycle (eg : appDelegate)
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"Annuler"];
and as of ios9 you could also use
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitle:@"Annuler"];
Swift version:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).title = "Annuler"
Hope that helps ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With