//(1)创建
UITextField *textField = [[UITextFieldalloc] init];
//(2)设置默认显示的字
textField.placeholder = @"请输入密码";
//(3)密码 YES就是密文,NO 明文
textField.secureTextEntry = NO;
//(4)设置边框以及边框颜色和大小
// UITextBorderStyleNone,无边框
// UITextBorderStyleLine,有边框
// UITextBorderStyleBezel,有边框和阴影
// UITextBorderStyleRoundedRect圆角
textField.borderStyle =UITextBorderStyleLine;
//当设置borderStyle为UITextBorderStyleRoundedRect会无效
// textField.background = [UIImage imageNamed:@"image_photo"];
//(5)设置边框大小和颜色
textField.layer.borderWidth =1;
textField.layer.borderColor = [UIColorredColor].CGColor;
// textField.layer.masksToBounds = YES;
// textField.layer.cornerRadius = 10;
//(7)设置键盘自动大小写的属性
textField.autocorrectionType =UITextAutocorrectionTypeNo;
//(8)设置是否有自动纠错
// UITextAutocorrectionTypeDefault, 默认
// UITextAutocorrectionTypeNo, 不自动纠错
// UITextAutocorrectionTypeYes, 自动纠错
textField.autocapitalizationType =UITextAutocapitalizationTypeNone;
//(9)设置左视图,可以起到距离左边框的作用
UIView * leftview = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 20, textField.frame.size.height )];//只有宽度起到了作用
textField.leftView = leftview;
leftview.backgroundColor = [UIColorwhiteColor];
//要设置左视图模式
textField.leftViewMode =UITextFieldViewModeAlways;
//(10)设置右边视图会影响到清除键
UIView * rightView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 20, textField.frame.size.height )];//只有宽度起到了作用
//textField.rightView = rightView;
rightView.backgroundColor = [UIColorwhiteColor];
//要设置右视图模式
textField.rightViewMode =UITextFieldViewModeAlways;
//(11)设置return键盘
// UIReturnKeyDefault, 默认灰色按钮,标有Return
// UIReturnKeyGo, 标有Go的蓝色按钮
// UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索
// UIReturnKeyJoin,标有Join的蓝色按钮
// UIReturnKeyNext,标有Next的蓝色按钮
// UIReturnKeyRoute,标有Route的蓝色按钮
// UIReturnKeySearch,标有Search的蓝色按钮
// UIReturnKeySend,标有Send的蓝色按钮
// UIReturnKeyYahoo,标有Yahoo的蓝色按钮
// UIReturnKeyYahoo,标有Yahoo的蓝色按钮
// UIReturnKeyEmergencyCall, 紧急呼叫按钮
textField.returnKeyType =UIReturnKeyDone;
//(12)键盘类型
//UIKeyboardTypeDefault, //当前键盘(默认)
// UIKeyboardTypeASCIICapable, //字母输入键
// UIKeyboardTypeNumbersAndPunctuation, //数字和符号
// UIKeyboardTypeURL, URL键盘
// UIKeyboardTypeNumberPad, 数字键盘
// UIKeyboardTypePhonePad, 电话号码输入键盘
// UIKeyboardTypeEmailAddress, //邮件地址输入键盘
textField.keyboardType =UIKeyboardTypeASCIICapable; //数字键
//(13)键盘风格
// UIKeyboardAppearanceDefault,默认外观,浅灰色
// UIKeyboardAppearanceAlert, 深灰 石墨色
textField.keyboardAppearance=UIKeyboardAppearanceDefault;
//(14)首字母是否大写
// UITextAutocapitalizationTypeNone, 不自动大写
// UITextAutocapitalizationTypeWords, 单词首字母大写
// UITextAutocapitalizationTypeSentences, 句子的首字母大写
// UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
textField.autocapitalizationType =UITextAutocapitalizationTypeAllCharacters;//所有字母大写
//(15)编辑时会出现个修改X,设置清除按钮模式
// UITextFieldViewModeNever,从不出现
// UITextFieldViewModeWhileEditing,编辑时显示
// UITextFieldViewModeUnlessEditing,不编辑时
// UITextFieldViewModeAlways 总是显示
textField.clearButtonMode =UITextFieldViewModeWhileEditing;
//(16)设置为YES当用点触文本字段时,字段内容会被清除
textField.clearsOnBeginEditing =YES;
//(17)设置为YES时文本会自动缩小以适应文本窗口大小。默认是保持原来大小,而让长文本滚动
textField.adjustsFontSizeToFitWidth =YES;
//(18)设置内容垂直方向
textField.contentVerticalAlignment =UIControlContentVerticalAlignmentBottom;
//(19)文字对齐方式
textField.textAlignment =NSTextAlignmentRight;
textField.frame = CGRectMake(20, 100, 200, 60);
[self.viewaddSubview:textField];