UITextField
2015-10-05 16:47
441 查看
//设置边框模式
tf.borderStyle = UITextBorderStyleRoundedRect;
//设置最小字体
tf.minimumFontSize = 15;
//设置默认文本
tf.text = @”username”;
//编辑时自动清空
tf.clearsOnBeginEditing = YES;
//设置删除按钮显示模式
tf.clearButtonMode = UITextFieldViewModeWhileEditing;
//开启密码输入模式
//tf.secureTextEntry = YES;
//垂直方向的对齐方式,容易忽略
tf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//水平方向的对齐方式
tf.textAlignment = NSTextAlignmentCenter;
//设置自动大写
tf.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
//自动校正模式(提示)
tf.autocorrectionType = UITextAutocorrectionTypeYes;
//设置键盘种类
//tf.keyboardType = UIKeyboardTypeNumberPad;
//设置代理
tf.delegate = self;
/设置正常状态下的背景图
tf.background = [UIImage imageNamed:@”normalbg”];
//设置禁用状态下的背景图,在tf.enabled为NO时显示
tf.disabledBackground = [UIImage imageNamed:@”disable”];
//设置左边视图||//设置右边视图,会覆盖掉clearButton
tf.leftView = leftView;
tf.leftViewMode = UITextFieldViewModeAlways;
//定制二级键盘
_textField.inputAccessoryView = [self customAccessoryView];
//设置主键盘
_textField.inputView = view;
//结束监听
[[NSNotificationCenter defaultCenter] removeObserver:self];
tf.borderStyle = UITextBorderStyleRoundedRect;
//设置最小字体
tf.minimumFontSize = 15;
//设置默认文本
tf.text = @”username”;
//编辑时自动清空
tf.clearsOnBeginEditing = YES;
//设置删除按钮显示模式
tf.clearButtonMode = UITextFieldViewModeWhileEditing;
//开启密码输入模式
//tf.secureTextEntry = YES;
//垂直方向的对齐方式,容易忽略
tf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//水平方向的对齐方式
tf.textAlignment = NSTextAlignmentCenter;
//设置自动大写
tf.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
//自动校正模式(提示)
tf.autocorrectionType = UITextAutocorrectionTypeYes;
//设置键盘种类
//tf.keyboardType = UIKeyboardTypeNumberPad;
//设置代理
tf.delegate = self;
/设置正常状态下的背景图
tf.background = [UIImage imageNamed:@”normalbg”];
//设置禁用状态下的背景图,在tf.enabled为NO时显示
tf.disabledBackground = [UIImage imageNamed:@”disable”];
//设置左边视图||//设置右边视图,会覆盖掉clearButton
tf.leftView = leftView;
tf.leftViewMode = UITextFieldViewModeAlways;
//代理方法之一 //是否结束编辑 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { if (textField.text.length < 6) { return NO; } return YES; }
//递归查找第一响应者,自己实现 - (UITextField *)searchFirstResponderOnView:(UIView *)view { for (UITextField *subView in view.subviews) { if ([subView isFirstResponder]) { return subView; } else { UITextField *grandchild = [self searchFirstResponderOnView:subView]; if (grandchild) { return grandchild; } } } return nil; }
//定制二级键盘
_textField.inputAccessoryView = [self customAccessoryView];
//设置主键盘
_textField.inputView = view;
#pragma mark - 监听键盘 -(void)monitorKeyboard { //监听键盘弹出 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //监听键盘收起 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; }
- (void)keyboardWillShow:(NSNotification *)news { //NSLog(@"%@", news.userInfo); NSValue *value = [news.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; //转换成frame CGRect frame = [value CGRectValue]; CGPoint center = _textField.center; center.y -= frame.size.height; _textField.center = center; }
- (void)keyboardWillHide:(NSNotification *)news { //NSLog(@"%@", news.userInfo); NSValue *value = [news.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; //转换成frame CGRect frame = [value CGRectValue]; CGPoint center = _textField.center; center.y += frame.size.height; _textField.center = center; }
//结束监听
[[NSNotificationCenter defaultCenter] removeObserver:self];
相关文章推荐
- Android UI SurfaceView的使用-绘制单个图型或多个图形
- require的定义看不懂【2】
- UITableViewCell中设置不同图片尺寸相同以及设置图片为圆形的方法
- ./configure -build,-host,-target设置
- hdu 1005 -- Number Sequence
- Java多线程15:Queue、BlockingQueue以及利用BlockingQueue实现生产者/消费者模型
- UITapGestureRecognizer 的用法
- UNIX环境高级编程中的apue.h头文件的问题
- UI_三个UITableView的省市区联动
- UITableView
- UVA_540: Team Queue
- break 和 return 和 continue
- mininet error: Cannot find required executable ovs-controller.
- HDU 5496(Beauty of Sequence-DP)
- poj 3566 Building for UN(为联合国而建)
- gFStu的UI控件
- POJ 3566 (弱校联萌十一大决战之厉兵秣马 B. Building for UN)
- u3d零基础学习之2d游戏学习笔记
- quicklisp 如何卸载本地项目
- 自定义UITableView每组头部控件