Change UISearchBar cancel button text in iOS 8

后端 未结 13 1772
感动是毒
感动是毒 2020-12-13 01:48

I\'d like to change the text from "Cancel" to "Done" of the Cancel button inside the UISearchBar in iOS 8. I am using UISearchControll

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 02:27

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

提交回复
热议问题