UITextField 弹出键盘的外观(类型)设置
2015-08-24 21:00
405 查看
UITextField 弹出键盘的外观(类型)设置
概要:
UITextField常用的键盘属性如:键盘类型,
安全输入等. 其实这些属性并不是UITextField特有的属性,
而是UITextInputTraits协议属性(一共有8个属性).
文章中尽量不使用或少使用封装, 目的是让大家清楚为了实现功能所需要的官方核心API是哪些(如果使用封装,
会在封装外面加以注释)
此文章由 @Scott 编写.
经 @春雨,@黑子
审核. 若转载此文章,请注明出处和作者
核心API
Class : UITextField
Delegate : UITextInputTraits
涉及的API:
/** 密文输入. */
@property(nonatomic,
getter=isSecureTextEntry)
BOOL secureTextEntry
/** 键盘类型. */
@property(nonatomic) UIKeyboardType keyboardType
/** 键盘上return按键类型. */
@property(nonatomic) UIReturnKeyType returnKeyType
/** 是否自动显示return按键*/
@property(nonatomic)
BOOL enablesReturnKeyAutomatically
/** 键盘显示类型 */
@property(nonatomic) UIKeyboardAppearance keyboardAppearance
/** 设置自动大写模式 */
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType
/** 设置自动纠正类型 */
@property(nonatomic) UITextAutocorrectionType autocorrectionType
/** 设置拼写检查类型 */
@property(nonatomic) UITextSpellCheckingType spellCheckingType
功能实现
Code:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20,
60, 200,
40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.placeholder = @"点击此处输入";
[self.view addSubview:textField];
/** 密文输入*/
textField.secureTextEntry = NO;
/**< YES 密文输入. NO
明文输入 */
/** 键盘类型 */
textField.keyboardType = UIKeyboardTypeDefault;
/**< 枚举值. */
/** 键盘上return按键类型. */
textField.returnKeyType = UIReturnKeyNext;
/**< 枚举值. */
/** 是否自动显示return按键*/
textField.enablesReturnKeyAutomatically = YES;
/**< 当用户开始输入时, return按键有效 */
/** 键盘显示类型 */
textField.keyboardAppearance = UIKeyboardAppearanceDark;
/**< 枚举值. */
/** 设置自动大写模式 */
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
/**< 枚举值,
每个单词首字母大写 */
/** 设置自动纠正类型 */
textField.autocorrectionType = UITextAutocorrectionTypeYes;
/**< 枚举值 */
/** 设置拼写检查类型 */
textField.spellCheckingType = UITextSpellCheckingTypeDefault;
/**< 枚举值 */
}
概要:
UITextField常用的键盘属性如:键盘类型,
安全输入等. 其实这些属性并不是UITextField特有的属性,
而是UITextInputTraits协议属性(一共有8个属性).
文章中尽量不使用或少使用封装, 目的是让大家清楚为了实现功能所需要的官方核心API是哪些(如果使用封装,
会在封装外面加以注释)
此文章由 @Scott 编写.
经 @春雨,@黑子
审核. 若转载此文章,请注明出处和作者
核心API
Class : UITextField
Delegate : UITextInputTraits
涉及的API:
/** 密文输入. */
@property(nonatomic,
getter=isSecureTextEntry)
BOOL secureTextEntry
/** 键盘类型. */
@property(nonatomic) UIKeyboardType keyboardType
/** 键盘上return按键类型. */
@property(nonatomic) UIReturnKeyType returnKeyType
/** 是否自动显示return按键*/
@property(nonatomic)
BOOL enablesReturnKeyAutomatically
/** 键盘显示类型 */
@property(nonatomic) UIKeyboardAppearance keyboardAppearance
/** 设置自动大写模式 */
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType
/** 设置自动纠正类型 */
@property(nonatomic) UITextAutocorrectionType autocorrectionType
/** 设置拼写检查类型 */
@property(nonatomic) UITextSpellCheckingType spellCheckingType
功能实现
Code:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20,
60, 200,
40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.placeholder = @"点击此处输入";
[self.view addSubview:textField];
/** 密文输入*/
textField.secureTextEntry = NO;
/**< YES 密文输入. NO
明文输入 */
/** 键盘类型 */
textField.keyboardType = UIKeyboardTypeDefault;
/**< 枚举值. */
/** 键盘上return按键类型. */
textField.returnKeyType = UIReturnKeyNext;
/**< 枚举值. */
/** 是否自动显示return按键*/
textField.enablesReturnKeyAutomatically = YES;
/**< 当用户开始输入时, return按键有效 */
/** 键盘显示类型 */
textField.keyboardAppearance = UIKeyboardAppearanceDark;
/**< 枚举值. */
/** 设置自动大写模式 */
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
/**< 枚举值,
每个单词首字母大写 */
/** 设置自动纠正类型 */
textField.autocorrectionType = UITextAutocorrectionTypeYes;
/**< 枚举值 */
/** 设置拼写检查类型 */
textField.spellCheckingType = UITextSpellCheckingTypeDefault;
/**< 枚举值 */
}
相关文章推荐
- UIScorllView和UIPageController的区别和实现图片轮播
- UIImageView动画 、自定义View 和手势的简单实用 Tom 猫 全部功能实现
- Android API Guides 安卓API指导----第一部分:Introduction(介绍)
- IOS UITextField 跳转到搜索界面
- Android UI之自定义AutoCompleteTextView
- StringBuffer和StringBuilder
- Android UI之自定义SeekBar
- UI -响应者链
- Easyui-Datagrid—表头灵活显示
- Design Pattern_Java:Builder Pattern
- UIView常用的方法
- Android UI设计:ListView适配器——ArrayAdapter、SimpleAdapter与BaseAdapter
- Go web之旅(Request分析)
- UIKeyboard
- Android UI设计——RadioButton和CheckBox控件
- STL Algorithms 之 unique
- Android UI之QuickContactBasge
- UItableView中的一些方法
- IOS-笔记14(UITextField,UITableView)
- HDU 5400(Arithmetic Sequence-暴力找区间)