UITextField 是UIControl的子类,UIControl又是UIView的子类,所以也是一个视图,只不过比UIView多了两个功能:(1)文字显示(2)文本编辑


创建对象
UITextField * field = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 220, 30)];


配置属性
field.backgroundColor = [UIColor whiteColor];


设置 边框样式


UITextBorderStyleNone,
UITextBorderStyleLine, 边框
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect 圆角

field.borderStyle = UITextBorderStyleRoundedRect;


设置输入框默显示(提示文字)的文字,但是不做为文本内容的一部分
field.placeholder = @"请输入用户名";


设置开始显示的文字
field.text = @"string";


设置文本颜色
field.textColor = [UIColor redColor];


对齐方式
field.textAlignment = NSTextAlignmentCenter;


文本字体
field.font = [UIFont fontWithName:@"Thonburi-Bold" size:20];


是否输入框是否可编辑
field.enabled = YES;


开始时清空输入框
field.clearsOnBeginEditing = YES;


是否文字以圆点格式显示 (设置密码模式)
field.secureTextEntry = YES;


设置弹出键盘的样式

field.keyboardType = UIKeyboardTypeNumberPad;


键盘右下角的显示的样式
field.returnKeyType = UIReturnKeyGo;

代理

代理使用步骤:
1.设置代理

field.delegate = self;
2.服从协议
UITextFieldDelegate

3.实现协议中的方法

(BOOL)textFieldShouldReturn:(UITextField *)textField


自定义输入视图
UIView * v1 = [[UIView alloc]initWithFrame:CGRectMake(200, 0, 568, 100)];
v1.backgroundColor = [UIColor redColor];
field.inputView = v1;


输入视图上方的辅助视图
field.inputAccessoryView = v1;


3.添加到父视图
[_View addSubview:field];


4.释放所有权
[field release];
}