UITextField 详解

 1 UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 280, 30)];
 2     tf.borderStyle = UITextBorderStyleNone; // 无边框线
 3     // UITextBorderStyleBezel(边框+阴影) ,UITextBorderStyleLine(边框线) ,UITextBorderStyleRoundedRect(圆角+阴影) 按钮样式
 4     tf.text = @"xxxxx";                 // 内容
 5     tf.placeholder = @"请输入姓名";       // 站位字符
 6     [tf becomeFirstResponder];          // 成为第一响应者,显示键盘
 7     [tf resignFirstResponder];          // 失去第一响应者,隐藏键盘
 8     
 9     tf.backgroundColor = [UIColor redColor];    // 背景色
10     tf.textColor = [UIColor greenColor];        // 字体颜色
11     tf.background = [UIImage imageNamed:@"background.png"]; // 设置背景图
12     
13     tf.clearButtonMode = UITextFieldViewModeNever;  //  没有清空按钮
14     tf.clearButtonMode = UITextFieldViewModeAlways; //  始终存在清空按钮
15     tf.clearButtonMode = UITextFieldViewModeWhileEditing;   // 在编辑时有清空按钮
16     tf.clearButtonMode = UITextFieldViewModeUnlessEditing;  // 编辑时没有清空按钮,其他时候都存在
17     
18     tf.clearsOnBeginEditing = YES;  //当编辑时,自动清空内容
19     
20     UIImageView *vv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"left.png"]];
21     tf.leftView = vv;   // 设置左侧图片
22     tf.rightView = vv;  // 设置右侧图片
23     tf.rightViewMode = tf.leftViewMode = UITextFieldViewModeAlways; //左右图片始终存在
24     
25     // UITextFieldDelegage UITextField监控代理
原文地址:https://www.cnblogs.com/sell/p/2891827.html