首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >以编程方式更改UITextField键盘类型

以编程方式更改UITextField键盘类型
EN

Stack Overflow用户
提问于 2011-09-05 01:43:07
回答 10查看 169.1K关注 0票数 178

是否可以通过编程方式更改uitextfield的键盘类型,这样就可以实现如下所示:

if(user is prompted for numeric input only)
    [textField setKeyboardType: @"Number Pad"];

if(user is prompted for alphanumeric input)
    [textField setKeyboardType: @"Default"];
EN

回答 10

Stack Overflow用户

回答已采纳

发布于 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];
票数 376
EN

Stack Overflow用户

发布于 2011-09-05 01:46:26

可以,例如:

[textField setKeyboardType:UIKeyboardTypeNumberPad];
票数 23
EN

Stack Overflow用户

发布于 2016-02-02 07:42:32

    textFieldView.keyboardType = UIKeyboardType.PhonePad

这是为了斯威夫特。此外,为了使其正常工作,它必须在textFieldView.delegate = self之后设置

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7301018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档