IOS控件UITextField详解
来源:互联网 发布:python3网络爬虫 编辑:程序博客网 时间:2024/05/17 03:26
UITextField,IOS中的输入控件,最常用到的控件之一。
创建UITextField并添加到视图上
只有设置了borderStyle才能被正确的显示,默认的样式一共有4种,分别是
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
文字字体相关的属性设置
文字对齐方式如下,IOS6已前的UITextAlignmentLeft已经过时
enum {
NSTextAlignmentLeft = 0,
NSTextAlignmentCenter = 1,
NSTextAlignmentRight = 2,
NSTextAlignmentJustified = 3,
NSTextAlignmentNatural = 4,
};
typedef enum {
UITextFieldViewModeNever, 重不出现
UITextFieldViewModeWhileEditing, 编辑时出现
UITextFieldViewModeUnlessEditing, 除了编辑外都出现
UITextFieldViewModeAlways 一直出现
} UITextFieldViewMode;
UITextAutocorrectionTypeDefault, 默认
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
} UITextAutocapitalizationType;
UIKeyboardTypeDefault, 默认键盘,支持所有字符
UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符
UIKeyboardTypeURL, URL键盘,支持.com按钮 只支持URL字符
UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话键盘
UIKeyboardTypeNamePhonePad, 电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点
UIKeyboardTypeTwitter, 优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
UIReturnKeyDefault, 默认 灰色按钮,标有Return
UIReturnKeyGo, 标有Go的蓝色按钮
UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索
UIReturnKeyJoin,标有Join的蓝色按钮
UIReturnKeyNext,标有Next的蓝色按钮
UIReturnKeyRoute,标有Route的蓝色按钮
UIReturnKeySearch,标有Search的蓝色按钮
UIReturnKeySend,标有Send的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyEmergencyCall, 紧急呼叫按钮
} UIReturnKeyType;
UIKeyboardAppearanceDefault, 默认外观,浅灰色
UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;
创建UITextField并添加到视图上
// 创建UITextFieldUITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 200, 30)];// 设置UITextField的样式textField.borderStyle = UITextBorderStyleRoundedRect;
只有设置了borderStyle才能被正确的显示,默认的样式一共有4种,分别是
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
文字字体相关的属性设置
// 设置默认文字内容textField.text = @"text";// 文字对齐方式textField.textAlignment = NSTextAlignmentLeft;// 文字颜色textField.textColor = [UIColor redColor];// 提示信息内容textField.placeholder = @"请输入内容";// 字体textField.font = [UIFont fontWithName:@"Arial" size:12.0];
文字对齐方式如下,IOS6已前的UITextAlignmentLeft已经过时
enum {
NSTextAlignmentLeft = 0,
NSTextAlignmentCenter = 1,
NSTextAlignmentRight = 2,
NSTextAlignmentJustified = 3,
NSTextAlignmentNatural = 4,
};
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容textField.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {
UITextFieldViewModeNever, 重不出现
UITextFieldViewModeWhileEditing, 编辑时出现
UITextFieldViewModeUnlessEditing, 除了编辑外都出现
UITextFieldViewModeAlways 一直出现
} UITextFieldViewMode;
//设置输入框的背景颜色,此时设置为白色 如果使用了自定义的背景图片边框会被忽略掉textField.backgroundColor = [UIColor whiteColor];//设置背景textField.background = [UIImage imageNamed:@"dd.png"];//设置背景 textField.disabledBackground = [UIImage imageNamed:@"cc.png"];
//是否纠错textField.autocorrectionType = UITextAutocorrectionTypeNo;typedef enum {
UITextAutocorrectionTypeDefault, 默认
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
//内容的垂直对齐方式 UITextField继承自UIControl,此类中有一个属性contentVerticalAlignmenttextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;//再次编辑就清空textField.clearsOnBeginEditing = YES; //设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动 textField.adjustsFontSizeToFitWidth = YES; //设置自动缩小显示的最小字体大小textField.minimumFontSize = 20;
//首字母是否大写textField.autocapitalizationType = UITextAutocapitalizationTypeNone;typedef enum {
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
} UITextAutocapitalizationType;
//设置键盘的样式textField.keyboardType = UIKeyboardTypeNumberPad;typedef enum {
UIKeyboardTypeDefault, 默认键盘,支持所有字符
UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符
UIKeyboardTypeURL, URL键盘,支持.com按钮 只支持URL字符
UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话键盘
UIKeyboardTypeNamePhonePad, 电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点
UIKeyboardTypeTwitter, 优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
//return键的样式textField.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;
//键盘外观textField.keyboardAppearance=UIKeyboardAppearanceDefault;typedef enum {
UIKeyboardAppearanceDefault, 默认外观,浅灰色
UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;
(本博文为博主原创,如需转载,请注明原文作者及文章来源。)
- IOS控件UITextField详解
- IOS控件UITextField详解
- IOS --控件UITextField详解
- ios-------------UITextField控件详解
- iOS UItextField控件详解
- IOS 控件 UITextField textField
- iOS UITextField控件
- iOS控件 ----- UITextField
- iOS UITextField控件
- iOS控件之UITextField
- iOS基础控件---UITextField
- 【iOS 开发】基本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
- 【IOS 开发】根本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
- iOS UITextField 详解
- iOS—UITextField详解
- iOS-- UITextField 详解
- ios-UITextField详解
- iOS中UITextField详解
- 系列文章:在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- Android permission 访问权限大全
- 新场,古镇隐于世775
- dasf
- 请求帮助啊?
- IOS控件UITextField详解
- 新Java运动:测试驱动开发3---用户注册4
- 起步即突发大情况 260
- ASIHTTPRequest with SSL
- dp,px,pt,sp 的区别 以及dp 和 px 互转
- dffa
- sqlite加密-SQLCipher
- gdb调试,交叉编译调试
- 使用intent调用Android系统自带应用