开发者

iOS and disabling keyboard search or enter key

Is there any way to disable the keyboard's search or enter buttons in iOS?

I'd like to disab开发者_JS百科le these while the text in my UISearchBar is too short to commit a search.


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.


Yes it possible to remove buttons of the default UIKeyboard.

For more information, including some URL's see:

Disabling keys on keyboard


enablesReturnKeyAutomatically to YES if you are using on uitextfield.It works for me.

textField.enablesReturnKeyAutomatically = YES / NO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜