UITextField
2015-07-21 14:12
399 查看
UITextField
一、UITextField:文本输入的控件
1、初始化一个UITextField
UITextField *pswTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 40)];
1、设置边框的类型
pswTextField.borderStyle = UITextBorderStyleRoundedRect;
2、提示的文字,当编辑时消失
pswTextField.placeholder = @"请输入密码";
3、设置键盘输入样式
pswTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
4、设置键盘显示样式
pswTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
5、设置成不是明文显示
pswTextField.secureTextEntry = YES;
6、设置键盘的返回样式
pswTextField.returnKeyType = UIReturnKeyNext;
7、设置清除按钮什么时候出现
pswTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
8、把需要放到TextField左边或者右边的视图赋值给TextField左边或者右边视图
pswTextField.leftView = left;
注:还需要设置左边或右边视图的样式
pswTextField.leftViewMode = UITextFieldViewModeAlways;
9、设置TextField的背景图片
pswTextField.background = [UIImage imageNamed:@“text.png”];
10、设置TextField禁用时的背景
pswTextField.disabledBackground = [UIImage imageNamed:@"text1.jpg"];
注:enabled:设置是否禁用(NO:禁用 YES:不禁用),默认YES
pswTextField.enabled = YES;
11、添加到View
[self.view addSubview:pswTextField];
二、代理:让别人帮忙做某件事(自己在本类实现不了的功能,让其他类帮忙实现)
1、如果要使用代理,需要先添加代理的协议
@interface ViewController : UIViewController<UITextFieldDelegate>
2、在使用的地方挂上代理(如果代理方法不执行,先检查是否挂上代理)
pswTextField.delegate = self;
三、方法:
1、已经开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"已经开始编辑!");
}
2、可以得到用户输入的单独字符
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSLog(@"%@", string);
return YES;
}
3、点击Return键的时候调用(标志已经编辑结束)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// 回收键盘
[textField resignFirstResponder];
return YES;
}
4、清空输入框内容的时候调用
- (BOOL)textFieldShouldClear:(UITextField *)textField {
NSLog(@"数据被清空啦~赶紧重新输入吧
一、UITextField:文本输入的控件
1、初始化一个UITextField
UITextField *pswTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 40)];
1、设置边框的类型
pswTextField.borderStyle = UITextBorderStyleRoundedRect;
2、提示的文字,当编辑时消失
pswTextField.placeholder = @"请输入密码";
3、设置键盘输入样式
pswTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
4、设置键盘显示样式
pswTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
5、设置成不是明文显示
pswTextField.secureTextEntry = YES;
6、设置键盘的返回样式
pswTextField.returnKeyType = UIReturnKeyNext;
7、设置清除按钮什么时候出现
pswTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
8、把需要放到TextField左边或者右边的视图赋值给TextField左边或者右边视图
pswTextField.leftView = left;
注:还需要设置左边或右边视图的样式
pswTextField.leftViewMode = UITextFieldViewModeAlways;
9、设置TextField的背景图片
pswTextField.background = [UIImage imageNamed:@“text.png”];
10、设置TextField禁用时的背景
pswTextField.disabledBackground = [UIImage imageNamed:@"text1.jpg"];
注:enabled:设置是否禁用(NO:禁用 YES:不禁用),默认YES
pswTextField.enabled = YES;
11、添加到View
[self.view addSubview:pswTextField];
二、代理:让别人帮忙做某件事(自己在本类实现不了的功能,让其他类帮忙实现)
1、如果要使用代理,需要先添加代理的协议
@interface ViewController : UIViewController<UITextFieldDelegate>
2、在使用的地方挂上代理(如果代理方法不执行,先检查是否挂上代理)
pswTextField.delegate = self;
三、方法:
1、已经开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"已经开始编辑!");
}
2、可以得到用户输入的单独字符
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSLog(@"%@", string);
return YES;
}
3、点击Return键的时候调用(标志已经编辑结束)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// 回收键盘
[textField resignFirstResponder];
return YES;
}
4、清空输入框内容的时候调用
- (BOOL)textFieldShouldClear:(UITextField *)textField {
NSLog(@"数据被清空啦~赶紧重新输入吧
相关文章推荐
- UILabel、UIButton
- iOS Interface builder was unable to determine the type of xxx.xib
- DAC模式登陆(解决对象名'sys.sysobjvalues'无效)
- UIlable 设置行间距
- Sybase ASE 查询结果保存到文件 output a SQL query results to a file
- java中PriorityQueue优先级队列使用方法
- iOS总结控件一(UILabel)
- ios学习之 初识UINavigationController
- while循环中,break,continue,return的区别
- UITableviewCell滑动出现多级的控制按钮 - UITableViewRowAction
- poj 1679 The Unique MST
- poj 1679 The Unique MST
- SolrJ、Request Handler
- 管理系统UI之四:使用全屏沉浸模式(Using Immersive Full-Screen Mode)
- 响应UI可见性的变化
- iOS8新特性之---- UIAlertController解析
- firefox os 2.1版本号UI接口方面有了质的飞跃
- POJ 1019 Number Sequence
- UITableView以及cell属性
- guestmount