UIkeyboard类型 [英] UIkeyboard type
问题描述
我想只使用字母键盘,如何限制它?我使用了以下语句,但它没有隐藏按数字转换键盘的按钮
I want to use only alphabetic keyboard, how to restrict it? I've used following statement but it doesn't hide the button that converts keyboard in numeric one
tempTextField.keyboardType = UIKeyboardTypeAlphabet;
推荐答案
我很害怕你不能只限制键盘输入字母字符。可用的keyboardTypes列在UITextInputTraits协议引用中,并且在头文件中有更多详细信息:
I'm affraid you cannot restrict the keyboard to only input alphabetic characters. The available keyboardTypes are listed in the UITextInputTraits protocol reference, and with even more detail in the header file:
typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space @ . prominently).
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
} UIKeyboardType;
我觉得SDK中缺少你想要的东西。我会向Apple提交一个错误报告,要求提供一种新的键盘类型,就像你提到的那样。
I feel what you want is missing from the SDK. I would file a bug report with Apple requesting a new keyboard type, like the one you mentioned.
除了提交错误报告并等待你之外,你有什么解决方案? SDK中可用的新键盘类型?检查文本字段中的输入。这可以通过分配UITextField的delegate属性,并实现UITextFieldDelegate方法textField:shouldChangeCharactersInRange:replacementString:来实现,如果替换字符串不包含数字,则只返回YES。
What is the solution for you besides filing a bug report and waiting for your new keyboard type to become available in the SDK? Checking the input in the textfield. This can be done by assigning the delegate property of the UITextField, and implementing the UITextFieldDelegate method textField:shouldChangeCharactersInRange:replacementString: and only return YES if the replacement string does not contain numbers.
HTH
这篇关于UIkeyboard类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!