UITextField 属性

- (void)viewDidLoad

{

    [super viewDidLoad];

    UITextField *input=[[UITextField alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];

    self.textfield=input;

    [input setText:@"hahah"];

    input.textAlignment=NSTextAlignmentCenter;

    input.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

    input.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;

    

    input.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];

    input.textColor=[UIColor blueColor];

    input.keyboardAppearance=UIKeyboardAppearanceLight;

//    input.alpha=0;

    

    input.tintColor=[[UIColor redColor] colorWithAlphaComponent:0.5];

    

    [self.view addSubview:input];

    

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   UITextField * myTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 50)];

     myTextField.backgroundColor = [UIColor clearColor];
     //简单设置textField的边缘样式
     myTextField.borderStyle = UITextBorderStyleRoundedRect;
     //占位显示的内容(水印)
     myTextField.placeholder = @ "请输入姓名" ;
     //对齐模式
     myTextField.textAlignment = NSTextAlignmentLeft ;
     //显示清除按钮的模式
     myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//    设置背景图
//    myTextField.disabledBackground
//    每次输入字符变成点.常用于密码输入
//    myTextField.secureTextEntry = YES;
     //再次编辑就清空
//    text.clearsOnBeginEditing = YES;
     //设置键盘的样式
//    text.keyboardType = UIKeyboardTypeNumberPad;
     //首字母是否大写
//    text.autocapitalizationType = UITextAutocapitalizationTypeNone;
     //return键变成什么键
//    text.returnKeyType =UIReturnKeyDone;
     //键盘外观
//    textView.keyboardAppearance=UIKeyboardAppearanceDefault;
     //按return键键盘往下收
//    becomeFirstResponder
     
     
     
     
//    UIView* view1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,40,0)];
//    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"music.png"]];
//    imageView.frame = CGRectMake(0,0,40,40);
//    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
//    imageView.image = [UIImage imageNamed:@"music.png"];
     
     
     
     
     
     
     //左视图,视图可以是UIView下的任意视图.
//    myTextField.leftView = imageView;
     //左视图的显示模式
//    myTextField.leftViewMode = UITextFieldViewModeAlways;
     //右视图
//    myTextField.rightView
     //右视图显示模式
//    myTextField.rightViewMode

转载于:https://www.cnblogs.com/zhibin/p/4115984.html

你可能感兴趣的:(UITextField 属性)