UITextField的详细使用
2012-05-17 17:46
295 查看
UItextField通常用于外部数据输入,以实现人机交互。下面以一个简单的登陆界面来讲解UItextField的详细使用。
![](http://pic002.cnblogs.com/images/2012/348285/2012042515334895.png)
//用来显示“用户名”的label
UILabel* label1 = [[UILabelalloc] initWithFrame:CGRectMake(15, 65, 70, 30)];
label1.backgroundColor = [UIColorclearColor];
label1.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];
label1.text = @"用户名";
label1.textColor = [UIColorwhiteColor];
[view1 addSubview:label1];
[label1 release];
UITextField * accountField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 60.0f, 190.0f, 40.0f)];
[accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
accountField.placeholder = @"用户名"; //默认显示的字
accountField.secureTextEntry = NO; //是否以密码形式显示
![](http://pic002.cnblogs.com/images/2012/348285/2012042515483546.png)
accountField.autocorrectionType = UITextAutocorrectionTypeNo;//设置是否启动自动提醒更正功能
accountField.autocapitalizationType = UITextAutocapitalizationTypeNone;
accountField.returnKeyType = UIReturnKeyDone; //键盘返回类型
accountField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
accountField.delegate = self;
accountField.keyboardType = UIKeyboardTypeDefault;//键盘显示类型
accountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //设置居中输入
accountField.scrollEnabled = YES;//是否可以拖动
accountField.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
//用来显示“密码”的label
UILabel* label2 = [[UILabelalloc] initWithFrame:CGRectMake(15, 120, 70, 30)];
label2.backgroundColor = [UIColorclearColor];
label2.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];
label2.text = @"密码";
label2.textColor = [UIColorwhiteColor];
[view1 addSubview:label2];
[label2 release];
UITextField* passwdField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 115.0f, 190.0f, 40.0f)];
[passwdFieldsetBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
//passwdField.placeholder = @"密码"; //默认显示的字
passwdField.secureTextEntry = YES; //密码类型
![](http://pic002.cnblogs.com/images/2012/348285/2012042515465397.png)
passwdField.autocorrectionType = UITextAutocorrectionTypeNo;
passwdField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwdField.returnKeyType = UIReturnKeyDone;
passwdField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
passwdField.delegate = self;
// passwdField.keyboardAppearance = UIKeyboardAppearanceDefault;
passwdField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
passwdField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
委托方法
-(void)textFieldDidBeginEditing:(UITextField *)textField;
//当开始点击textField会调用的方法
-(void)textFieldDidEndEditing:(UITextField *)textField;
//当textField编辑结束时调用的方法
//按下Done按钮的调用方法,我们让键盘消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
![](http://pic002.cnblogs.com/images/2012/348285/2012042515334895.png)
//用来显示“用户名”的label
UILabel* label1 = [[UILabelalloc] initWithFrame:CGRectMake(15, 65, 70, 30)];
label1.backgroundColor = [UIColorclearColor];
label1.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];
label1.text = @"用户名";
label1.textColor = [UIColorwhiteColor];
[view1 addSubview:label1];
[label1 release];
UITextField * accountField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 60.0f, 190.0f, 40.0f)];
[accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
accountField.placeholder = @"用户名"; //默认显示的字
accountField.secureTextEntry = NO; //是否以密码形式显示
![](http://pic002.cnblogs.com/images/2012/348285/2012042515483546.png)
accountField.autocorrectionType = UITextAutocorrectionTypeNo;//设置是否启动自动提醒更正功能
accountField.autocapitalizationType = UITextAutocapitalizationTypeNone;
accountField.returnKeyType = UIReturnKeyDone; //键盘返回类型
accountField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
accountField.delegate = self;
accountField.keyboardType = UIKeyboardTypeDefault;//键盘显示类型
accountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //设置居中输入
accountField.scrollEnabled = YES;//是否可以拖动
accountField.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
//用来显示“密码”的label
UILabel* label2 = [[UILabelalloc] initWithFrame:CGRectMake(15, 120, 70, 30)];
label2.backgroundColor = [UIColorclearColor];
label2.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];
label2.text = @"密码";
label2.textColor = [UIColorwhiteColor];
[view1 addSubview:label2];
[label2 release];
UITextField* passwdField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 115.0f, 190.0f, 40.0f)];
[passwdFieldsetBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
//passwdField.placeholder = @"密码"; //默认显示的字
passwdField.secureTextEntry = YES; //密码类型
![](http://pic002.cnblogs.com/images/2012/348285/2012042515465397.png)
passwdField.autocorrectionType = UITextAutocorrectionTypeNo;
passwdField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwdField.returnKeyType = UIReturnKeyDone;
passwdField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
passwdField.delegate = self;
// passwdField.keyboardAppearance = UIKeyboardAppearanceDefault;
passwdField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
passwdField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
委托方法
-(void)textFieldDidBeginEditing:(UITextField *)textField;
//当开始点击textField会调用的方法
-(void)textFieldDidEndEditing:(UITextField *)textField;
//当textField编辑结束时调用的方法
//按下Done按钮的调用方法,我们让键盘消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
相关文章推荐
- UITextField的详细使用
- UITextField的详细使用
- UITextField的详细使用
- UITextField的详细使用
- UITextField的详细使用
- iOS uitextfield详细使用说明
- STM32使用FIR滤波器的详细过程
- HashMap的详细介绍(源码解析)和使用实例
- JS中showModalDialog 详细使用
- Keil MDK从未有过的详细使用讲解
- JavaScript alert()函数详细使用说明
- Delphi中ShellExecute使用详解(详细解释10种显示状态)
- Git详细使用文档
- XV6700 最详细的使用说明
- 有关phpmailer的详细介绍及使用方法
- CXImage600 详细使用配置说明教程
- 虚拟机安装详细图解教程及使用教程
- Linux输入输出重定向详细使用说明
- 使用scrapy爬取京东产品详细信息
- 在Python中使用__slots__方法的详细教程