iOS_UITextField 基本操作
2015-06-02 21:51
381 查看
基本操作
UITextField *userNameTextField = [[UITextField alloc] init]; userNameTextField.frame = CGRectMake(30, 100, 220, 50); [self.window addSubview:userNameTextField]; [userNameTextField release]; // 设置样式 userNameTextField.borderStyle = UITextBorderStyleRoundedRect; userNameTextField.placeholder = @"Enter your name"; userNameTextField.text = @"OUTLAN"; userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; // 设置右边删除按钮出现时间 UILabel *leftLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; leftLable.text = @"N"; // 设置左右视图的显示时间 userNameTextField.leftView = leftLable; userNameTextField.leftViewMode = UITextFieldViewModeAlways; [leftLable release]; userNameTextField.enabled = YES; // 设置是否允许输入 userNameTextField.clearsOnBeginEditing = NO; // 输入时清空 userNameTextField.secureTextEntry = NO; // 呈现圆点,一般用于输入密码 userNameTextField.keyboardAppearance = UIKeyboardAppearanceDark; // 控制键盘颜色为黑 userNameTextField.keyboardType = UIKeyboardTypeEmailAddress; // 设置键盘样式 userNameTextField.returnKeyType = UIReturnKeySearch; // 设置return按键的样式 UIView *keyBoard = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 300)]; keyBoard.backgroundColor = [UIColor greenColor]; // userNameTextField.inputView = keyBoard; // 替换键盘 [keyBoard release]; UIView *inputAccessView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)]; inputAccessView.backgroundColor = [UIColor yellowColor]; userNameTextField.inputAccessoryView = inputAccessView; // 辅助条 [inputAccessView release];
收回键盘
设置代理对象,通常为self
// 设置代理 textFiled.delegate = self;
当前类遵守协议
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate>
实现协议方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField { NSLog(@"点击了Return"); [textField resignFirstResponder]; // 放弃第一响应者 收回键盘 return YES; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { NSLog(@"begining"); return YES; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { NSLog(@"ending"); return YES; }
相关文章推荐
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'yintingting_baisi/Info.plist'.
- Android Volley完全解析(三),定制自己的Request
- iOS_UIButton 简单操作
- iOS按钮UIButton常用属性总结
- UIScrollView代理方法
- easyui换主题,并记录在cookie.以及cookie作用域介绍
- java 的builder模式——设计思想
- .net mvc4 从客户端中检测到有潜在危险的 Request.Form 值
- IIC(Inter-Integrated Circuit)总线协议浅谈
- iOS开发UI篇—UITableview控件简单介绍
- Android Call requires API level 19 (current min is 11)
- OpenCV学习笔记(四十七)——VideoWriter生成视频流highgui
- 自定义UITableViewCell 上的多个按钮点击事件处理
- iOS-学习笔记-UI-第一天
- 6.2 视图UIView及视图控制器(UIViewController)
- ajax阻塞UI线程
- HDU 2227 Find the nondecreasing subsequences(DP)
- Arduino--Helloworld!
- 多线程编程(一)之 block 与 dispatch quene
- request.getParameter() 获取中文乱码