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];