您的位置:首页 > 产品设计 > UI/UE

iOS之UI学习-UITextField属性篇

2016-05-09 14:38 477 查看
- (void)viewDidLoad { 

     [super viewDidLoad];

     //须知:UITextField继承于UIcontrol,而UITextView继承于UIScrollView,UIScrollView又继承于UIView 

     //创建输入框 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 280, 100)];

     //设置输入框的边框样式(共四种样式) 

     // textField.borderStyle = UITextBorderStyleNone; 没有边框样式

     // textField.borderStyle = UITextBorderStyleLine; 边框是黑线 

     // textField.borderStyle = UITextBorderStyleBezel; 边框线类似于灰线

     textField.borderStyle = UITextBorderStyleRoundedRect; //边框是圆角的,背景颜色默认是白色的

     //设置输入框在没有内容时候的提示文字

     textField.placeholder = @"输入框没有内容时的提示内容";

     //设置字体的样式和大小

     textField.font = [UIFont fontWithName:@"Arial" size:16];

     //设置输入框的最右边的删除按钮(共四种情况)

     // textField.clearButtonMode = UITextFieldViewModeNever; 不显示删除按钮

     // textField.clearButtonMode = UITextFieldViewModeWhileEditing; 编辑的时候显示删除按钮

     // textField.clearButtonMode = UITextFieldViewModeUnlessEditing; 只在编辑的时候不显示删除按钮

     textField.clearButtonMode = UITextFieldViewModeAlways; //只要有内容存在则存在删除按钮 

     //隐藏输入的字符

     textField.secureTextEntry = NO;

     //再次编辑清空上一次内容

     textField.clearsOnBeginEditing = YES;

     //自动纠错

     textField.autocorrectionType = UITextAutocorrectionTypeDefault; //默认

     // textField.autocorrectionType = UITextAutocorrectionTypeNo; 不自动纠错

     // textField.autocorrectionType = UITextAutocorrectionTypeYes; 自动纠错 

     //设置这两项之后,字符数量超出之后,全部的字符的大小会变到设置的最小值

     textField.adjustsFontSizeToFitWidth = YES; 

     textField.minimumFontSize = 9; 

     //设置进行输入时候的键盘类型 

     textField.keyboardType = UIKeyboardTypeDefault;

     // textField.keyboardType = UIKeyboardTypeASCIICapable;                    支持ASCII的键盘

     // textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;   包含数字和一些#等字符的键盘

     // textField.keyboardType = UIKeyboardTypeURL;                                    带有.com的键盘

     // textField.keyboardType = UIKeyboardTypeNumberPad;                        纯数字键盘

     // textField.keyboardType = UIKeyboardTypePhonePad;                          电话键盘(数字键盘和带有#*的键盘)

     // textField.keyboardType = UIKeyboardTypeNamePhonePad;                 以下的键盘都类似

   
b5ce
 // textField.keyboardType = UIKeyboardTypeEmailAddress;

     // textField.keyboardType = UIKeyboardTypeDecimalPad;

     // textField.keyboardType = UIKeyboardTypeTwitter;

     // textField.keyboardType = UIKeyboardTypeWebSearch;

     // textField.keyboardType = UIKeyboardTypeAlphabet; 

     //键盘的return键 

     textField.returnKeyType = UIReturnKeyDefault;             //在这些类型中,最后一个单词是什么则显示什么

     // textField.returnKeyType = UIReturnKeyGo;

     // textField.returnKeyType = UIReturnKeyGoogle;

     // textField.returnKeyType = UIReturnKeyJoin;

     // textField.returnKeyType = UIReturnKeyNext;

     // textField.returnKeyType = UIReturnKeyRoute;

     // textField.returnKeyType = UIReturnKeySearch;

     // textField.returnKeyType = UIReturnKeySend;

     // textField.returnKeyType = UIReturnKeyYahoo;

     // textField.returnKeyType = UIReturnKeyDone;

     // textField.returnKeyType = UIReturnKeyEmergencyCall;

     // textField.returnKeyType = UIReturnKeyContinue;

     //键盘的外观 textField.keyboardAppearance = UIKeyboardAppearanceDefault;

     // textField.keyboardAppearance = UIKeyboardAppearanceDark; 黑色键盘

     // textField.keyboardAppearance = UIKeyboardAppearanceLight; 白色键盘

     // textField.keyboardAppearance = UIKeyboardAppearanceAlert; 黑色键盘 

     //内容的首字母是否大写 

     textField.autocapitalizationType = UITextAutocapitalizationTypeNone;                  //不自动改成大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeWords;             将单词的首字母大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;       将句子的首字母大写

     // textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;  所有字母都大写 

    //添加到当前视图 [self.view addSubview:textField];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: