是否可以通过编程方式更改uitextfield的键盘类型,这样就可以实现如下所示:
if(user is prompted for numeric input only)
[textField setKeyboardType: @"Number Pad"];
if(user is prompted for alphanumeric input)
[textField setKeyboardType: @"Default"];
发布于 2011-09-05 01:46:04
UITextField
有一个keyboardType
属性
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).
UIKeyboardTypeDecimalPad, // A number pad including a decimal point
UIKeyboardTypeTwitter, // Optimized for entering Twitter messages (shows # and @)
UIKeyboardTypeWebSearch, // Optimized for URL and search term entry (shows space and .)
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
} UIKeyboardType;
你的代码应该是
if(user is prompted for numeric input only)
[textField setKeyboardType:UIKeyboardTypeNumberPad];
if(user is prompted for alphanumeric input)
[textField setKeyboardType:UIKeyboardTypeDefault];
发布于 2011-09-05 01:46:26
可以,例如:
[textField setKeyboardType:UIKeyboardTypeNumberPad];
发布于 2016-02-02 07:42:32
textFieldView.keyboardType = UIKeyboardType.PhonePad
这是为了斯威夫特。此外,为了使其正常工作,它必须在textFieldView.delegate = self
之后设置
https://stackoverflow.com/questions/7301018
复制相似问题