UITextField * accountField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 60.0f, 190.0f, 40.0f)];
[accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
accountField.placeholder = @"用户名"; //默认显示的字
accountField.autocorrectionType = UITextAutocorrectionTypeNo;//设置是否启动自动提醒更正功能
accountField.autocapitalizationType = UITextAutocapitalizationTypeNone;
accountField.returnKeyType = UIReturnKeyDone; //键盘返回类型
accountField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
accountField.delegate = self;
accountField.keyboardType = UIKeyboardTypeDefault;//键盘显示类型
accountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //设置居中输入
accountField.scrollEnabled = YES;//是否可以拖动
委托方法
-(void)textFieldDidBeginEditing:(UITextField *)textField;
//当开始点击textField会调用的方法
-(void)textFieldDidEndEditing:(UITextField *)textField;
//当textField编辑结束时调用的方法
//按下Done按钮的调用方法,我们让键盘消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
原文:http://www.cnblogs.com/linxiu-0925/p/5058110.html