UITextField简单使用方法:
//初始化
UITextField *text = [ [UITextField alloc] initWithFrame: CGRectMake(20, 20, 200, 200) ];
//设置边框样式
text.borderStyle = UITextBorderStyleRoundedRect;
typedef enum {
UITextBorderStyleNone;
UITextBorderStyleLine;
UITextBorderStyleBezel;
UITextBorderStyleRoundedRect;
} UITextBorderStyle;
//设置输入框的背景图片
text.background = [UIImage imageNamed: @"image.png"];
//设置输入框的背景颜色 如果使用了图片背景,会被忽略
text.backgroundColor = [UIColor blackColor];
//默认显示的提示字,水印提示
text.placeholder = @"请输入密码:";
//设置输入框一开始就有的文本
text.text = @"文本";
//设置输入框文本内容的字体样式和大小
text.font = [UIFont fontWithName:@"Arial" size: 20];
//设置字体颜色
text.textColor = [UIColor redColor];
//设置文本内容对齐方式
text.textAlignment = UITextAlignmentLeft;
//垂直对齐方式
text.contentVerticalAlignment = UIContentVerticalAlignmentLeft;
//设置为输入后变点,用于密码输入时
text.secureTextEntry = YES;
//设置文本自动纠错
text.autocorrectionType = UITextAutocorrectionTypeNo;
//设置一次性删除的叉的显示位置
text.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {
UITextFieldViewModeNever; //从不出现
UITextFieldViewModeWhileEditing; //写入文本时出现
UITextFieldViewModeUnlessEditing; //除了写入文本是出现
UITextFieldViewModeAlways; //一直出现
} UITextFieldViewMode;
//再次编辑就清空
text.clearsOnBeginEditing = YES;
//文本自动适应窗口大小, 默认是保持原来大小,让长文本滚动
text.adjustsFontSizeToFitWidth = YES;
//适应窗口时最小字体大小
text.minimunFontSize = 20;
//设置首字母大写
text.autocapitalizationType = UITextAutocapitailizationTypeNone;
//最左侧加图片
UIImageView *image = [ [UIImageView alloc] initWithImage: [UIImage imageNamed: @"left.png"]];
text.rightView = image;
text.rightViewMode = UITextFieldViewModeAlways;
//设置键盘样式
text.keyboardType = UIKeyboardTypeNumberPad; //数字键盘
//键盘外观
text.keyboardAppearance = UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault;
UIKeyboardAppearanceAlert; //深灰 石墨色
}UIKeyboardAppearanceType;