iOS_UI_3_UITextField
2015-08-30 22:10
369 查看
一. UITextField定义
UITextField(文本框): 继承于 UIControl UICotrol继承于UIView, 用于显示 编辑 文本.
二. UITextField的创建
同UILabel类似
三. UITextField中文本显示属性
四 . 文本框样式
五. 文本的输入控制
UITextField(文本框): 继承于 UIControl UICotrol继承于UIView, 用于显示 编辑 文本.
二. UITextField的创建
同UILabel类似
[code]// 创建并初始化文本框 UITextField *aTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 100, 100, 30)]; //设置背景图片: 和UILable设置背景图片一样 //设置背景色 aTextField.backgroundColor = [UIColor greenColor]; //添加到window [self.window addSubview:aTextField];
三. UITextField中文本显示属性
[code]// 文本显示 aTextField.text = @"welcom"; // 在文本框内显示 welcom aTextField.textColor = [UIColor lightGrayColor]; // 文本框中的字体颜色 aTextField.font = [UIFont fontWithName: @"Helvetica-Bold" size:20]; // 设置字体 样式和大小 aTextField.placeholder = @"请输入"; // 占位字符串(没有任何输入时,给出的提示字符串) aTextField.adjustsFontSizeToFitWidth = YES; //文本会是否自动缩小以适应文本窗口大小. 默认NO aTextField.clearsOnBeginEditing = YES; // 再次是否编辑清空文本框 aTextField.secureTextEntry = YES; // 输入的字符是否以圆点显示 默认NO(用于设置 密码的输入方式)
[code]//设置文本框输入文字时,是否自动纠错 aTextField.autocorrectionType = UITextAutocorrectionTypeNo; /* typedef enum { UITextAutocorrectionTypeDefault, // 默认 UITextAutocorrectionTypeNo, //不自动纠错 UITextAutocorrectionTypeYes, //自动纠错 } UITextAutocorrectionType; */
[code]//设置字母大小写 aTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; /* typedef enum { UITextAutocapitalizationTypeNone, // 不自动大写 UITextAutocapitalizationTypeWords, // 单词首字母大写 UITextAutocapitalizationTypeSentences, // 句子的首字母大写 UITextAutocapitalizationTypeAllCharacters, // 所有字母都大写 } UITextAutocapitalizationType; */
[code]// 设置文本对齐方式 aTextField.textAlignment = NSTextAlignmentCenter; // 文本框中字的对齐方式 //文本的齐方式 /* Values for NSTextAlignment */ typedef NS_ENUM(NSInteger, NSTextAlignment) { NSTextAlignmentLeft = 0, // Visually left aligned 左对齐 #if TARGET_OS_IPHONE NSTextAlignmentCenter = 1, // Visually centered 剧中对齐 NSTextAlignmentRight = 2, // Visually right aligned 右对齐 #else /* !TARGET_OS_IPHONE */ NSTextAlignmentRight = 1, // Visually right aligned NSTextAlignmentCenter = 2, // Visually centered #endif NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned. 段落中的最后一行是自然对齐 NSTextAlignmentNatural = 4, // Indicates the default alignment for script 表示默认对齐 } NS_ENUM_***AILABLE_IOS(6_0);
四 . 文本框样式
[code]//设置边框样式 aTextField.borderStyle = UITextBorderStyleRoundedRect; /* typedef enum { UITextBorderStyleNone, // 无样式 UITextBorderStyleLine, // 只显示边框线 UITextBorderStyleBezel, // 斜视图 边框样式 UITextBorderStyleRoundedRect // 圆角边框样式 } UITextBorderStyle; */ //输入框中是否有个叉号,用于一次性删除输入框中的内容 aTextField.clearButtonMode = UITextFieldViewModeAlways; /* typedef enum { UITextFieldViewModeNever, // 无 UITextFieldViewModeWhileEditing, // 编辑时出现 UITextFieldViewModeUnlessEditing, // 没有编辑时出现 UITextFieldViewModeAlways // 一直有 } UITextFieldViewMode; */
五. 文本的输入控制
[code] aTextField.enabled = YES; // 是否允许默认键盘输入 默认值为YES aTextField.returnKeyType = UIReturnKeyNext; // 键盘右下角的return按钮以Next 显示 // 自定义一个视图 UIView *myInputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)]; myInputView.backgroundColor = [UIColor magentaColor]; //***重点:从默认键盘位置弹出一个自定义视图(一般用于自定义键盘, 如,拨号键盘等) aTextField.inputView = myInputView; // 弹出自己定义的键盘输入 默认是系统键盘 aTextField.inputAccessoryView = myAccessoryView; // 输入视图上方的辅助视图(默认nil) 如, 拨号键盘上方的 显示号码框
[code]//设置键盘样式 aTextField.keyboardType = UIKeyboardTypeNumberPad; /* // 键盘类型 typedef enum { UIKeyboardTypeDefault, //默认键盘,支持所有字符 UIKeyboardTypeASCIICapable, //支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation, //标准电话键盘,支持+*#字符 UIKeyboardTypeURL, // URL键盘,支持.com按钮 只支持URL字符 UIKeyboardTypeNumberPad, // 数字键盘 UIKeyboardTypePhonePad, // 电话键盘 UIKeyboardTypeNamePhonePad, // 电话键盘,也支持输入人名 UIKeyboardTypeEmailAddress, // 用于输入电子 邮件地址的键盘 UIKeyboardTypeDecimalPad, // 数字键盘 有数字和小数点 UIKeyboardTypeTwitter, // 优化的键盘,方便输入@、#字符 } UIKeyboardType; */ //设置键盘外观 aTextField.keyboardAppearance=UIKeyboardAppearanceDefault; /* // 键盘外观 typedef enum { UIKeyboardAppearanceDefault, // 浅灰色(默认) UIKeyboardAppearanceAlert, // 深灰 (石墨色) } UIReturnKeyType; */ //returnKeyType return键样式 /* typedef NS_ENUM(NSInteger, UIReturnKeyType) { UIReturnKeyDefault, // 默认 UIReturnKeyGo, // return 键为 GO UIReturnKeyGoogle, // Google UIReturnKeyJoin, // Join UIReturnKeyNext, // Next UIReturnKeyRoute, //Route UIReturnKeySearch, // Search UIReturnKeySend, // Send UIReturnKeyYahoo, // Yahoo UIReturnKeyDone, // Done UIReturnKeyEmergencyCall, // EmergencyCall( 急电 ) }; */
相关文章推荐
- iOS:UIToolBar、toolbarItems、BarButtonItem的几种关系
- UIday05:target/action设计模式 代理设计模式 UIImageView ⼿势识别器
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- UIday05_zy02: 代理设计模式
- easyui中data-options用法
- UIday05_zy01:target/action 设计模式
- IOS基础UI之(二)图片预览
- IOS UITableView删除功能
- [Bluetooth Core V4.2 ] VOL2, PartB, 4 Logical Transports
- 第5组UI "让你的界面酷炫到底"-ViewAniMator之ViewSwitcher、ImageSwitcher(图像切换器)、TextSwitcher(文本切换器)、ViewFlipper
- IOS UITableView拖动排序功能
- iOS_UI_2_Label
- css3媒体查询Medai Queries小例
- Longest Consecutive Sequence 数组连续数字的情况
- 《第一行代码》读书笔记(三)----UI开发(下)
- easyUI comboTree的实现
- Ajax之X-Requested-With请求头
- AlertDialog.Builder用法
- 北京传智播客网页UI设计学院
- [c#美味] Guid ToString 格式知多少?