UITextField的键盘种类、用法总结

参考自:iOS键盘的相关设置

1.键盘风格

UIKit框架支持如下几种键盘风格:html

代码 xib(Keyboard Type) 风格释义
UIKeyboardTypeDefault Default 默认键盘,支持全部字符
UIKeyboardTypeASCIICapable ASCII Capable 支持ASCII的键盘
UIKeyboardTypeNumbersAndPunctuation Numbers and Punctuation 数字和标点符号键盘
UIKeyboardTypeURL URL 用于输入URL的键盘
UIKeyboardTypeNumberPad Number Pad 数字键盘(只有数字)
UIKeyboardTypePhonePad Phone Pad 电话键盘(数字、+*#)
UIKeyboardTypeNamePhonePad Name Phone Pad 支持输入人名的电话键盘
UIKeyboardTypeEmailAddress E-mail Address 用于输入邮件地址的键盘
UIKeyboardTypeDecimalPad Decimal Pad 小数键盘(比数字键盘多一个小数点)
UIKeyboardTypeTwitter Twitter 一种优化的推特文本输入键盘
UIKeyboardTypeWebSearch Web Search 略(iOS7.0之后才支持)
UIKeyboardTypeAlphabet 等于UIKeyboardTypeASCIICapable 已通过时

代码中的用法:

textField.keyboardType = UIKeyboardTypeNumberPad;ios

xib中的用法:参照表格设置属性便可!

2.键盘外观

代码 xib(Appearance) 释义
UIKeyboardAppearanceDefault Default 默认外观:浅灰色
UIKeyboardAppearanceAlert Dark 深灰:石墨色
UIKeyboardAppearanceDark Dark 深灰:石墨色(iOS7.0之后,用于替代UI…Alert)
UIKeyboardAppearanceLight Light 亮灰:趋近于白色

代码中的用法:

textField.keyboardAppearance = UIKeyboardAppearanceAlert;web

xib中的用法:参照表格设置属性便可!

3.自动大写

代码 xib(Capitalization) 释义
UITextAutocapitalizationTypeNone None 不自动大写
UITextAutocapitalizationTypeWords Words 单词首字母大写
UITextAutocapitalizationTypeSentences Sentences 句子首字母大写
UITextAutocapitalizationTypeAllCharacters All Characters 全部字母大写

代码中的用法:

textField.autocapitalizationType = UITextAutocapitalizationTypeWords;api

xib中的用法:参照表格设置属性便可!

4.自动更正

代码 xib() 释义
UITextAutocorrectionTypeDefault Default 默认
UITextAutocorrectionTypeNo No 不自动更正
UITextAutocorrectionTypeYes Yes 自动更正

代码中的用法:

textField.autocorrectionType = UITextAutocorrectionTypeYes;安全

xib中的用法:参照表格设置属性便可!

5.安全文本输入

textField.secureTextEntry = YES;
或者在xib中勾选 Secure Text Entry框架