iOS 提供了10种键盘类型,在开发中,我们可以根据不同的需求,选择不同的键盘样式,例如,当我们只需要输入手机号码时,可以选择纯数字类型的键盘(NumbersAndPunctuation),当我们需要输入网址时,可以选择URL样式的键盘(UIKeyboardTypeURL),其中,默认的键盘样式(UIKeyboardTypeDefault)就是(UIKeyboardTypeNamePhonePad)样式。
我们可以通过输入框的 keyboardType 来设置键盘样式
UITextField.keyboardType = UIKeyboardTypeNamePhonePad;
1、 UIKeyboardTypeDefault,
// Default type for the current input method.
2、 UIKeyboardTypeASCIICapable,
// Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
3、 UIKeyboardTypeNumbersAndPunctuation,
// Numbers and assorted punctuation.
4、 UIKeyboardTypeURL,
// A type optimized for URL entry (shows . / .com prominently).
5、 UIKeyboardTypeNumberPad,
// A number pad (0-9). Suitable for PIN entry.
6、 UIKeyboardTypePhonePad,
// A phone pad (1-9, *, 0, #, with letters under the numbers).
7、 UIKeyboardTypeNamePhonePad,
// A type optimized for entering a person‘s name or phone number.
8、 UIKeyboardTypeEmailAddress,
// A type optimized for multiple email address entry (shows space @ . prominently).
9、 UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1),
// A number pad with a decimal point.
10、 UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0),
// A type optimized for twitter text entry (easy access to @ #)
11、 UIKeyboardTypeWebSearch NS_ENUM_AVAILABLE_IOS(7_0),
// A default keyboard type with URL-oriented addition (shows space . prominently).
下面一图像展示区别
UIKeyboardTypeDefault
UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL
UIKeyboardTypeNumberPad
UIKeyboardTypePhonePad
UIKeyboardTypeEmailAddress
UIKeyboardTypeDecimalPad
UIKeyboardTypeTwitter
UIKeyboardTypeWebSearch
时间: 2024-10-11 21:50:34