I am developing an Application where I wanted to change the text of Search String in the SearchBar. I wanted to change the text of Cancel Button Also which appears next to the SearchBar. Before entering any string in the search bar we wil get the Search String as the default string. I wanted to change the text of that string and when we click on that searchbar we get a cancel button next to searchbar and I wanted to change the text of that cancel button.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
On iOS 7, if you've set
displaysSearchBarInNavigationBar = YES
onUISearchDisplayController
, replacing the cancel button title via subview recursion or the appearance proxy will not work.Instead, use your own bar button in
viewDidLoad
:Solution for iOS 7. All credits for this go to Mr. Jesper Nielsen - he wrote the code.
Jeremytripp 's working Code in Swift
I couldn't find the same code in Swift so I "translated" it myself:
If you're still having trouble with changing the Cancel button in iOS7, this is currently working for me:
I would like to fix the UIAppearance technique, as yar1vn code won't work with Xcode 5. With the following you will have code that works perfectly for both iOS 6 and iOS 7.
First, you need to understand that the cancel button is a private UINavigationButton:UIButton. Hence, it is not an UIBarButtonItem. After some inspection, it appears that UINavigationButton will respond to those UIAppearance selectors:
Coincidentally, those selectors match those of a UIBarButtonItem. Meaning the trick is to use two separate UIAppearance to handle the private class UINavigationButton.
Now, this technique works for the Cancel button, but it also works for the Back button if you change the barClass to
[UINavigationBar self]
.This solution work for me - iOs7 and iOs8:
and