uitextfield 键盘类型_IOS 单行文本输入框 UITextField 使用

UITextField 继承 UIControl 类,只支持单行输入和显示,可输入密码类型。支持实现代理 UITextFieldDelegate

属性名称类型说明默认值textNSString文本输入值

textColorUIColor文本颜色

UIFontUIFont文本大小

textAlignmentNSTextAlignment文本方向NSLeftTextAlignment

borderStyleUITextBorderStyle边框风格UITextBorderStyleNone

placeholderNSString提示文本

clearsOnBeginEditingBOOL开始编辑时候清空内容NO

adjustsFontSizeToFitWidthBOOL以宽度自动调整字体大小NO

backgroundUIImage背景

clearButtonModeUITextFieldViewMode设置什么时候显示清除按钮UITextFieldViewModeNever

leftViewUIView左边视图

rightViewUIView右边视图

inputViewUIView响应输入时候显示的视图

leftViewModeUITextFieldViewMode设置什么时候显示左边视图模式UITextFieldViewModeNever

rightViewModeUITextFieldViewMode设置什么时候显示右边视图模式UITextFieldViewModeNever

API- (BOOL)endEditing:(BOOL)force; 是否强制取消当前输入行为

##### 代理协议函数

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; 当开始编辑前,返回NO可以阻止编辑

- (void)textFieldDidBeginEditing:(UITextField *)textField 当编辑输入结束触发

(BOOL)textFieldShouldEndEditing:(UITextField *)textField 结束编辑前,返回NO可以阻止编辑结束

(void)textFieldDidEndEditing:(UITextField *)textField 编辑结束

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 当输入内容发生改变触发,range表示改变位置和长度。返回NO可阻止改变

- (void)textFieldDidChangeSelection:(UITextField *)textField 输入内容发生改变后触发,IOS13支持。

- (BOOL)textFieldShouldClear:(UITextField *)textField 当内容发生清除触发,返回NO阻止清除(BOOL)textFieldShouldReturn:(UITextField *)textField 当按下回车键触发,返回NO可阻止默认行为

参考代码UITextField* _textField = [[UITextField alloc] init];

// 设置位置

_textField.frame = CGRectMake(50, 100, 300, 60);

// 设置圆角边框风格

_textField.borderStyle = UITextBorderStyleRoundedRect;

// 设置值

_textField.text = @"";

// 设置提示语

_textField.placeholder = @"请输入用户名";

// 设置键盘类型

_textField.keyboardType = UIKeyboardAppearanceDefault;

// 设置代理

_textField.delegate = self;

// 设置是否为密码类型

_textField.secureTextEntry = NO;

UITextField* _passwdText = [[UITextField alloc] init];

_passwdText.frame = CGRectMake(50, 200, 300, 60);

_passwdText.borderStyle = UITextBorderStyleRoundedRect;

_passwdText.placeholder = @"请输入密码";

_passwdText.keyboardType = UIKeyboardAppearanceDefault;

_passwdText.secureTextEntry = YES;

[self.view addSubview:_textField];

[self.view addSubview:_passwdText];

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值