問題描述
我只想使用字母鍵盤,如何限制呢?我使用了以下語句,但它沒有隱藏將鍵盤轉換為數(shù)字的按鈕
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;
推薦答案
恐怕您不能將鍵盤限制為只能輸入字母字符.UITextInputTraits 協(xié)議參考中列出了可用的鍵盤類型,并且在頭文件中提供了更多詳細信息:
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 的委托屬性,并實現(xiàn) UITextFieldDelegate 方法 textField:shouldChangeCharactersInRange:replacementString: 并僅在替換字符串不包含數(shù)字時返回 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
這篇關于UI鍵盤類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!