iOS Change the title of cancel button in UISearchBar

前端 未结 13 1941
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 10:35

I wish to change the title of the cancel button in iOS. I have been using this previously:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayCon         


        
13条回答
  •  旧巷少年郎
    2020-12-28 11:07

    Chiming in with the code I used inside the UIKitUISearchResultsUpdating protocol method updateSearchResults(for searchController: UISearchController):

    if let cancelButton : UIButton = searchController.searchBar.value(forKey: "_cancelButton") as? UIButton {
        cancelButton.setTitle("Back", for: UIControlState.normal)
    }
    

    (iOS 10, Swift 3.0)

提交回复
热议问题