uitextfield的常用属性

    //文本框
    UITextField *textField=[[UITextField alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];
    //textField.backgroundColor=[UIColor yellowColor];
    
//文本显示设置
    //文字
    textField.text=@"110";//提前输入的文字,可以删除
    //文字颜色
    textField.textColor=[UIColor redColor];
    //文字对其位置
    textField.textAlignment=NSTextAlignmentRight;
    //文字大小
    textField.font=[UIFont systemFontOfSize:25];
    //输入提示
    textField.placeholder=@"请输入";
//输入控制设置
    //是否允许输入,YES允许输入,NO不允许输入,默认为YES
    //textField.enabled=YES;
    //是否清空(开始输入是否清空之前文字.默认NO)
    textField.clearsOnBeginEditing=YES;
    //密码
    textField.secureTextEntry=YES;
    //键盘
    textField.keyboardType=UIKeyboardTypeNumberPad;//纯数字键盘
    
    
    
    UIView *keyBoardView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    keyBoardView.backgroundColor=[UIColor redColor];
    //1.取代键盘位置的view,以后可以自己定义按钮输入
    //textField.inputView=keyBoardView;
    
    //2.在原来键盘上面 ,加一块view,上部可以实现自定义按钮输入
    textField.inputAccessoryView=keyBoardView;
    
    
    
//外观设置
    //输入框形状
    textField.borderStyle=UITextBorderStyleRoundedRect;
    
    
    
    UIImageView *imV=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
    imV.frame=CGRectMake(0, 0, 50, 50);
    //在文本框左边显示一张图片
    textField.leftView=imV;
    textField.leftViewMode=UITextFieldViewModeAlways;
    
    
    UIImageView *imV1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
    imV1.frame=CGRectMake(0, 0, 50, 50);
    //在文本框右边显示一张图片
    textField.rightView=imV1;
    textField.rightViewMode=UITextFieldViewModeAlways;
    
    //清楚文本内部文字 按钮
    textField.clearButtonMode=UITextFieldViewModeAlways;
    
    
    [backGroundView addSubview:textField];
    

原文地址:https://www.cnblogs.com/-ios/p/4672578.html