美文网首页
UIKit之UITextField

UIKit之UITextField

作者: MI移动 | 来源:发表于2017-07-20 09:50 被阅读0次
#import "TestController.h"

@interface TestController ()
@property (strong, nonatomic)UITextField *textField;
@end

@implementation TestController

- (void)viewDidLoad {
    [super viewDidLoad];

}


#pragma mark - lazyload
- (UITextField *)textField{
    if (!_textField) {
        _textField = [UITextField new];
        _textField.backgroundColor= [UIColor grayColor];
        [self.view addSubview:_textField];
        
        // 默认显示内容
        _textField.text=@"请输入账号:";
        
        // 内容字体颜色
        _textField.textColor= [UIColor redColor];
        
        // 内容对其方式
        _textField.textAlignment=NSTextAlignmentLeft;
        
        // 内容字体类型和字体大小
        _textField.font= [UIFont fontWithName:@"Helvetica-Bold"size:20];//黑体加粗20号字
        
        // 占位字符串(没有任何输入时,给出的提示字符串)颜色稍淡
        _textField.placeholder=@"账号:";
        
        // 是否允许输入(BOOL值)
        _textField.enabled=YES;//默认是YES
        
        // 是否开始输入的时候清空输入框内容(BOOL值)
        _textField.clearsOnBeginEditing=YES;//首次输入时删除程序里面自定义的_textField.text  //默认是NO
        
        // 是否文字以圆点格式显示(BOOL值)
         _textField.secureTextEntry = YES;//加密模式  (密码输入框可用)
        
        // 设置Textfield弹出键盘类型(枚举值)
        _textField.keyboardType = UIKeyboardTypePhonePad;
    
        // 设置Textfield弹出键盘风格(外表)
        _textField.keyboardAppearance = UIKeyboardAppearanceDark;
        
        // 键盘右下角return按钮的类型(枚举值)
        _textField.returnKeyType = UIReturnKeyNext;
       
        // 设置Textfield边界风格(枚举值)
        _textField.borderStyle=UITextBorderStyleRoundedRect;
        
        // 设置清除按钮(枚举值)
        _textField.clearButtonMode=UITextFieldViewModeAlways;//总是显示清除按钮
        
        // 自定义输入视图(默认是键盘)
//        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
//        view1.backgroundColor = [UIColor redColor];
//        _textField.inputView = view1;
        
        // 输入视图上方的辅助视图(默认nil值)
        UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
        view2.backgroundColor = [UIColor yellowColor];
        _textField.inputAccessoryView =view2;
        
        UIView*view3 = [[UIView alloc]initWithFrame:CGRectMake(0,0,50,50)];
        view3.backgroundColor= [UIColor greenColor];
    
        // 左视图和他的显示模式
        _textField.leftView=view3;
        _textField.leftViewMode=UITextFieldViewModeAlways;//总是显示左视图
        
        // 右视图和他的显示模式
        _textField.rightView = view3;
        _textField.rightViewMode = UITextFieldViewModeAlways;//总是显示右视图
        
    }
    return _textField;
}
@end

相关文章

  • UIKit之UITextField

  • UIKit之UITextField篇

    1.初始化控件 (文本输入控件) 特殊初始化 2.设置基本属性及用法 frame:设置UITextField的显示...

  • UIKit - UITextField

    属性 属性名作用borderStyleUITextBorderStyleLine : 矩形,黑色边框,透明背景UI...

  • UIKit-UITextField

    初始化textfield并设置位置及大小 UITextField *text = [[UITextField al...

  • UIKit-UITextField

    UIKit系列常见处理办法集合 点击任何地方收缩键盘 return 回收键盘 修改textField的placeh...

  • iOS之Text Kit

    简介 UIKit框架中用来展示文本的类有UITextView、UITextField、UILabel,其中U...

  • UILabel实现复制

    UIKit框架里的能够支持复制的,很自然就会想到UITextView、UITextField、UIWebView。...

  • Swift-UIKit-UITextField

    1.描述 官方描述: 一个用于展示用户界面上,可编辑文本区域的对象(An object that displays...

  • iOS-UIMenuController搭配UIPasteboa

    基本概念 UIKit框架中,可以直接执行拷贝黏贴操作的有 : UITextView、UITextField和UIW...

  • 键盘的相关设置(UITextfield)

    转自:键盘的相关设置(UITextfield) 一、键盘风格 UIKit框架支持8种风格键盘。 typedef e...

网友评论

      本文标题:UIKit之UITextField

      本文链接:https://www.haomeiwen.com/subject/fakdkxtx.html