UITextField常用设置小结
来源:互联网 发布:人工智能 ppt模板 编辑:程序博客网 时间:2024/05/04 15:31
1、UITextField的初始化和基本设置
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 240.0f, 30.0f)]; [myTextField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型 myTextField.placeholder =@"test"; //默认显示的字 myTextField.returnKeyType = UIReturnKeyDone; //什么类型的回车按钮 //清空输入的字符模式,设为永不显示清空按钮;UITextFieldViewModeWhileEditing则是在编辑状态时(及获得焦点)显示清空按钮 myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
设置delegate为自己,以便响应软键盘回车键事件
myTextField.delegate=self;
设置完delegate之后,响应软键盘回车键事件
-(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; //软键盘的撤回 return YES;}
[textField becomeFirstResponder];
//设置UITextField右边图像 UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]]; myTextField.rightView=imgv; myTextField.rightViewMode = UITextFieldViewModeAlways; //总是显示
2、捕获UITextField的变化
//因为UITextField也是UIController,所以可以通过加一个消息事件的方式来响应文本的变化 [myTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
处理函数
- (void) textFieldDidChange:(id) sender { UITextField *textField = (UITextField *)sender; NSLog(@"the text is:%@",textField.text);}
- UITextField常用设置小结
- Swift UITextField常用设置
- UITextField的常用设置
- UITextField常用属性设置
- UITextField - 常用属性及设置
- iOS UITextField常用的设置
- UITextField小结
- UITextField小结
- UITextField小结
- UITextField小结
- uitextField 小结
- UITextField小结
- UITextField小结
- UITextField小结
- UITextField小结
- UITextField小结
- UITextField小结
- UITextField小结
- 趋势科技移动客户端病毒报告
- ubuntu 更新错误
- poj 1976 A Mini Locomotive(01背包)
- AWR
- java-当中的I/O(2)( 第33集)
- UITextField常用设置小结
- Download ACCU Overload Journal
- Ubuntu 10.04 amd64,中文输入法乱码、开发Android等
- 看书笔记---管理控制文件和重做日志文件
- 第五次c程序上机报告
- 线索二叉树的实现
- 10130 - SuperSale
- TFS 安装与管理
- Qt-4.7.2移植过程