1.键盘风格
UIKit框架支持以下几种键盘风格:
| 代码 | 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 | 一种优化的推特文本输入键盘 | |
| UIKeyboardTypeWebSearch | Web Search | 略(iOS7.0以后才支持) |
| UIKeyboardTypeAlphabet | 等于UIKeyboardTypeASCIICapable | 已经过时 |
代码中的用法:
textField.keyboardType = UIKeyboardTypeNumberPad;
xib中的用法:参照表格设置属性即可!
2.键盘外观
| 代码 | xib(Appearance) | 释义 |
|---|---|---|
| UIKeyboardAppearanceDefault | Default | 默认外观:浅灰色 |
| UIKeyboardAppearanceAlert | Dark | 深灰:石墨色 |
| UIKeyboardAppearanceDark | Dark | 深灰:石墨色(iOS7.0以后,用于替代UI…Alert) |
| UIKeyboardAppearanceLight | Light | 亮灰:趋近于白色 |
代码中的用法:
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
xib中的用法:参照表格设置属性即可!
3.自动大写
| 代码 | xib(Capitalization) | 释义 |
|---|---|---|
| UITextAutocapitalizationTypeNone | None | 不自动大写 |
| UITextAutocapitalizationTypeWords | Words | 单词首字母大写 |
| UITextAutocapitalizationTypeSentences | Sentences | 句子首字母大写 |
| UITextAutocapitalizationTypeAllCharacters | All Characters | 所有字母大写 |
代码中的用法:
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
xib中的用法:参照表格设置属性即可!
4.自动更正
| 代码 | xib() | 释义 |
|---|---|---|
| UITextAutocorrectionTypeDefault | Default | 默认 |
| UITextAutocorrectionTypeNo | No | 不自动更正 |
| UITextAutocorrectionTypeYes | Yes | 自动更正 |
代码中的用法:
textField.autocorrectionType = UITextAutocorrectionTypeYes;
xib中的用法:参照表格设置属性即可!
5.安全文本输入
textField.secureTextEntry = YES;
或者在xib中勾选 Secure Text Entry
本文详细介绍了UIKit框架下iOS设备的键盘样式配置,包括不同类型的键盘风格、键盘外观、自动大写选项、自动更正功能及安全文本输入设置。通过代码示例与XIB文件设置指导,帮助开发者更好地掌握iOS键盘定制技巧。
2132

被折叠的 条评论
为什么被折叠?



