Is there any way to disable the keyboard's search or enter buttons in iOS?
I'd like to disable these while the text in my UISearchBar
is too short to commit a search.
Go to Settings > Accessibility > Keyboards, tap Full Keyboard Access, then turn on Full Keyboard Access.
Remove a keyboard: Tap Edit, tap. next to the keyboard you want to remove, tap Delete, then tap Done. Reorder your keyboard list: Tap Edit, drag.
It's worth noting that you can change enablesReturnKeyAutomatically
on the text field, this will cause the return/done key to be disabled when there is no text in the text field.
// default is NO (when YES, will automatically disable return key when text widget has zero-length contents, and will automatically enable when text widget has non-zero-length contents)
However as SK9 has I'm sure noticed you can't specify rules for when it should be enabled and disabled.
I can't find any class named UISearchView - did you mean UISearchBar? If so, keep reading...
You can't disable (gray out) the button programmatically. Implement the searchBar:shouldChangeTextInRange:replacementText:
method on the UISearchBarDelegate
to check for the replacement text @"\n" (thats the return key press) and if they have entered enough text to allow it to search, and do nothing if they haven't.
If you really want to disable the return key, you can build your own keyboard view (with no framework keyboard to inherit from to get existing functionality) and return it from the inputView property of a UITextView
(which means building your own search view as well)
There is a very simple solution to this with no UI hacks, no accessing Apple private apis and such. Simply add this to viewDidLoad.
yourSearchBar.enablesReturnKeyAutomatically = true
As per Apples documentation:
If you set it to true, the keyboard disables the Return key when the text entry area contains no text. As soon as the user enters some text, the Return key is automatically enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With