UITextField的使用
来源:互联网 发布:用python求最大公约数 编辑:程序博客网 时间:2024/06/04 21:15
UITextField的使用
borderStyle:文本框的边框风格
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
autocorrectionType:可以设置是否启动自动提醒更正功能。
placeholder:设置默认的文本显示
returnKeyType:设置键盘完成的按钮
backgroundColor:设置背景颜色
delegate:设置委托
//设置输入框的背景颜色,此时设置为白色如果使用了自定义的背景图片边框会被忽略掉
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];
//设置焦点:
[UITextField becomeFirstResponder];
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
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;
typedef enum {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
} UITextFieldViewMode;
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
autocorrectionType:可以设置是否启动自动提醒更正功能。
placeholder:设置默认的文本显示
returnKeyType:设置键盘完成的按钮
backgroundColor:设置背景颜色
delegate:设置委托
//设置输入框的背景颜色,此时设置为白色如果使用了自定义的背景图片边框会被忽略掉
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];
//设置焦点:
[UITextField becomeFirstResponder];
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
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;
typedef enum {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
} UITextFieldViewMode;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
UITextField* text = [[
UITextField
alloc
]
initWithFrame
:CGRectMake(
1
0
,
5
0
,
3
0
0
,
3
0
)];
text
.borderStyle
=
UITextBorderStyleRoundedRect
;
text
.autocorrectionType
=
UITextAutocorrectionTypeYes
;
text
.placeholder
=
@"您好,请输入。。。。"
;
text
.returnKeyType
=
UIReturnKeyDone
;
//相应的还有“Return”"Go""Google"等
text
.clearButtonMode
=
UITextFieldViewModeWhileEditing
;
[text
setBackgroundColor
:[
UIColor
whiteColor
]];
text
.delegate
=
self
;
[
self
.view
addSubview
:text];
//=======================
-(
void
)textFieldDidBeginEditing:(
UITextField
*)textField{
//当开始点击textField会调用的方法
}
-(
void
)textFieldDidEndEditing:(
UITextField
*)textField{
//当textField编辑结束时调用的方法
}
//按下Done按钮的调用方法,我们让键盘消失
-(
BOOL
)textFieldShouldReturn:(
UITextField
*)textField{
[textField
resignFirstResponder
];
return
YES
;
}
- UITextField的使用
- UITextField的使用
- UITextField的使用
- UITextField的详细使用
- UITextField的使用详解
- UITextField的使用
- UITextField的详细使用
- UITextField的详细使用
- UITextField的使用详解
- UITextField的使用
- UITextField的使用详解
- UITextField的使用
- UITextField的使用详解
- UITextField 的使用
- UITextField的使用
- UITextField的使用
- iOS UITextField的使用
- UITextField 的使用
- ajax 导致浏览器卡死
- C++多重继承与虚基类
- 在python用import或者from...import来导入相应的模块
- 有趣的C++对象工厂
- SQLite的SQL语法
- UITextField的使用
- 报告称2012美国84%成年人每天上网 50%有智能机
- 【游戏开发备注之三】GameCenter登陆出现“无法识别此游戏”问题的两种解决方法
- inf文件示例
- D3D_DRIVER_TYPE枚举
- QString与String
- HDU 2421 质因子分解
- rman-03009错误的一个原因
- 黑马程序员—面向对象(基础)