关于ios:我可以在iPad上使用哪个UIKeyboardType

Which UIKeyboardType can I use on the iPad

我的iPad应用程序中有一个textField对象。 我想给用户一个方便的键盘来输入数字。 在我的代码中,我添加了:

1
2
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.keyboardType = UIKeyboardTypeDecimalPad;

根据文档,这是有效的键盘类型,但是当我编辑文本字段时,会出现普通的ASCII键盘。 但是,当我将其更改为:

1
textField.keyboardType = UIKeyboardTypePhonePad;

键盘如下所示:
phonepad keyboard

理想情况下,我想要一个只包含数字和小数点的键盘,但是在iPad上这不可能吗? 有谁明确列出了iPhone和iPad上可以使用的键盘? 苹果在这一点上还不清楚。 我也看到了类似的问题,但没有一个答案能真正解决我的观点。


这些是可以在两个iOS设备上使用的UIKeyboardTypes。从文档:

  • UIKeyboardTypeDefault

    • Use the default keyboard for the current input method.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeASCIICapable

    • Use a keyboard that displays standard ASCII characters.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeNumbersAndPunctuation

    • Use the numbers and punctuation keyboard.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeURL

    • Use a keyboard optimized for URL entry. This type features".","/", and".com" prominently.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeNumberPad

    • Use a numeric keypad designed for PIN entry. This type features the numbers 0 through 9 prominently. This keyboard type does not
      support auto-capitalization.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypePhonePad

    • Use a keypad designed for entering telephone numbers. This type features the numbers 0 through 9 and the"*" and"#" characters
      prominently. This keyboard type does not support auto-capitalization.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeNamePhonePad

    • Use a keypad designed for entering a person’s name or phone number. This keyboard type does not support auto-capitalization.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeEmailAddress

    • Use a keyboard optimized for specifying email addresses. This type features the"@","." and space characters prominently.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeDecimalPad

    • Use a keyboard with numbers and a decimal point.
    • Available in iOS 4.1 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeTwitter

    • Use a keyboard optimized for twitter text entry, with easy access to the @ and # characters.
    • Available in iOS 5.0 and later.
    • Declared in UITextInputTraits.h.
  • UIKeyboardTypeAlphabet

    • Deprecated.
    • Use UIKeyboardTypeASCIICapable instead.
    • Available in iOS 2.0 and later.
    • Declared in UITextInputTraits.h.

这是不同类型的键盘的一些屏幕截图。


收到警告后,我使用模拟器测试了适用于iPad / iPhone的键盘类型

"Can't find keyplane that supports type 8 for keyboard
Wildcat-Landscape-QWERTY-Pad; using
2592645918_Wildcat-Alphabetic-Keyboard_Capital-Letters"

在iPad上UIKeyboardTypeDecimalPad。希望这对下一个在这里跌倒的人有用。

iPad:

  • UIKeyboardTypeASCIICapable
  • UIKeyboardTypeNumbersAndPunctuation
  • UIKeyboardTypeURL
  • UIKeyboardTypeNumberPad
  • UIKeyboardTypeNamePhonePad
  • UIKeyboardTypeEmailAddress
  • UIKeyboardTypeTwitter

因此,除UIKeyboardTypeDecimalPad以外的所有字符。在iOS 5.1或6.1中,使用UIKeyboardTypeDecimalPad只会给您带来一记耳光。

苹果手机:

  • UIKeyboardTypeASCIICapable
  • UIKeyboardTypeNumbersAndPunctuation
  • UIKeyboardTypeURL
  • UIKeyboardTypeNumberPad
  • UIKeyboardTypeNamePhonePad
  • UIKeyboardTypeEmailAddress
  • UIKeyboardTypeDecimalPad
  • UIKeyboardTypeTwitter

即所有人