Styling the cancel button in a UISearchBar

前端 未结 21 1392
-上瘾入骨i
-上瘾入骨i 2020-12-02 09:13

I have a UISearchBar that has a cancel button (it\'s displayed using -(void)setShowsCancelButton:animated). I\'ve changed the tintColor of the sear

21条回答
  •  温柔的废话
    2020-12-02 10:15

    Change the title of 'Cancel' button:

    [[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"newTitle" forState:UIControlStateNormal];
    

    Swift equivalent:

       let cancelButton = UIButton.appearance(whenContainedInInstancesOf: [UISearchBar.self])
       cancelButton?.setTitle("cancel".localized, for: .normal)
    

提交回复
热议问题