How can I disable/enable UISearchBar keyboard's Search button?
You can't disable the search button. What you can do is use the UISearchBarDelegate
methods to figure out if you should take action on the search button being clicked, like so:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { if (searchBar.text.length < 2) { return; } else { // Do search stuff here }}
The Apple Documentation for this is very useful as well, and is a great starting point for customizing the searchBar's behavior.
Short answer is no...
Longer, hackier and more exotic one is here:How to disable/enable the return key in a UITextField?
You can do it by accessing UISearchBar
property.
let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextFieldtextFieldInsideSearchBar?.enablesReturnKeyAutomatically = false
By playing with enablesReturnKeyAutomatically
property you can achieve your requirements.
Thanks.