UITextField 弹出键盘的外观(类型)设置

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; /**< 枚举值 */



}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值