textfield有很多功用要领,这里引见一部分:
//初始化textfield并设置位置及大小
UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];
//设置边框款式,只要设置了才会显现边框款式
text.borderStyle = UITextBorderStyleRoundedRect;
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
//设置输入框的背景色彩,此时设置为白色 假如使用了自定义的背景图片边框会被疏忽掉
text.backgroundColor = [UIColor whiteColor];
//设置背景
text.background = [UIImage imageNamed:@"dd.png"];
//设置背景
text.disabledBackground = [UIImage imageNamed:@"cc.png"];
//当输入框没有内容时,水印提醒 提醒内容为password
text.placeholder = @"password";
//设置输入框内容的字体款式和大小
text.font = [UIFont fontWithName:@"Arial" size:20.0f];
//设置字体色彩
text.textColor = [UIColor redColor];
//输入框中是不是有个叉号,在什么时候显现,用于一次性删除输入框中的内容
text.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {
UITextFieldViewModeNever, 重不涌现
UITextFieldViewModeWhileEditing, 编辑时涌现
UITextFieldViewModeUnlessEditing, 除了编辑外都涌现
UITextFieldViewModeAlways 一向涌现
} UITextFieldViewMode;
//输入框中一最先就有的笔墨
text.text = @"一最先就在输入框的笔墨";
//每输入一个字符就变成点 用语暗码输入
text.secureTextEntry = YES;
//是不是纠错
text.autocorrectionType = UITextAutocorrectionTypeNo;
typedef enum {
UITextAutocorrectionTypeDefault, 默许
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
//再次编辑就清空
text.clearsOnBeginEditing = YES;
//内容对齐体式格局
text.textAlignment = UITextAlignmentLeft;
//内容的垂直对齐体式格局 UITextField继续自UIControl,此类中有一个属性contentVerticalAlignment
text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//设置为YES时文本会自动减少以顺应文本窗口大小.默许是坚持本来大小,而让长文本转动
textFied.adjustsFontSizeToFitWidth = YES;
//设置自动减少显现的最小字体大小
text.minimumFontSize = 20;
//设置键盘的款式
text.keyboardType = UIKeyboardTypeNumberPad;
typedef enum {
UIKeyboardTypeDefault, 默许键盘,支撑一切字符
UIKeyboardTypeASCIICapable, 支撑ASCII的默许键盘
UIKeyboardTypeNumbersAndPunctuation, 规范电话键盘,支撑+*#字符
UIKeyboardTypeURL, URL键盘,支撑.com按钮 只支撑URL字符
UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话键盘
UIKeyboardTypeNamePhonePad, 电话键盘,也支撑输入人名
UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点
UIKeyboardTypeTwitter, 优化的键盘,轻易输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
//首字母是不是大写
text.autocapitalizationType = UITextAutocapitalizationTypeNone;
typedef enum {
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 一切字母都大写
} UITextAutocapitalizationType;
//return键变成什么键
text.returnKeyType =UIReturnKeyDone;
typedef enum {
UIReturnKeyDefault, 默许 灰色按钮,标有Return
UIReturnKeyGo, 标有Go的蓝色按钮
UIReturnKeyGoogle, 标有Google的蓝色按钮,用语搜刮
UIReturnKeyJoin, 标有Join的蓝色按钮
UIReturnKeyNext, 标有Next的蓝色按钮
UIReturnKeyRoute, 标有Route的蓝色按钮
UIReturnKeySearch, 标有Search的蓝色按钮
UIReturnKeySend, 标有Send的蓝色按钮
UIReturnKeyYahoo, 标有Yahoo的蓝色按钮
UIReturnKeyYahoo, 标有Yahoo的蓝色按钮
UIReturnKeyEmergencyCall, 紧要呼唤按钮
} UIReturnKeyType;
//键盘表面
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault, 默许表面,浅灰色
UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;
//设置代办 用于完成协定
text.delegate = self;
//把textfield加到视图中
[self.window addSubview:text];
//最右边加图片是以下代码 左边相似
UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
text.rightView=image;
text.rightViewMode = UITextFieldViewModeAlways;
以上就是textfield是什么意义啊的细致内容,更多请关注ki4网别的相干文章!