UITextField控件 -- @ShinePug
2015-12-27 21:40
381 查看
一、UITextField手动编写控件
UITextField *txtAccount = [[UITextField alloc] initWithFrame:CGRectMake(10, 10,300, 30)];
// 设置委托
[txtAccount setDelegate:self];
// 设置占位符
[txtAccount setPlaceholder:@"账号"];
// 设置文本对齐
[txtAccount setTextAlignment:NSTextAlignmentLeft];
// 设置样式
[txtAccount setBorderStyle:UITextBorderStyleRoundedRect];
// 加入view中
[self.view addSubview:
txtAccount];
[txtAccount release];
二、UITextFieldDelegate委托
// 设置输入框,是否可以被修改
// NO-将无法修改,不出现键盘
// YES-可以修改,默认值
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return YES;
}
// 当点击键盘的返回键(右下角)时,执行该方法。
// 一般用来隐藏键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (txtAccount == textField) {
[txtAccount resignFirstResponder];
}
return YES;
}
// 当输入框获得焦点时,执行该方法。
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"textFieldDidBeginEditing");
}
// 指定是否允许文本字段结束编辑,允许的话,文本字段会失去first
responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
// 文本框失去first
responder 时,执行
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
}
// 指明是否允许根据用户请求清除内容
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
return YES;
}
// 文本框的文本,是否能被修改
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string{
return YES;
}
UITextField *txtAccount = [[UITextField alloc] initWithFrame:CGRectMake(10, 10,300, 30)];
// 设置委托
[txtAccount setDelegate:self];
// 设置占位符
[txtAccount setPlaceholder:@"账号"];
// 设置文本对齐
[txtAccount setTextAlignment:NSTextAlignmentLeft];
// 设置样式
[txtAccount setBorderStyle:UITextBorderStyleRoundedRect];
// 加入view中
[self.view addSubview:
txtAccount];
[txtAccount release];
二、UITextFieldDelegate委托
// 设置输入框,是否可以被修改
// NO-将无法修改,不出现键盘
// YES-可以修改,默认值
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return YES;
}
// 当点击键盘的返回键(右下角)时,执行该方法。
// 一般用来隐藏键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (txtAccount == textField) {
[txtAccount resignFirstResponder];
}
return YES;
}
// 当输入框获得焦点时,执行该方法。
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"textFieldDidBeginEditing");
}
// 指定是否允许文本字段结束编辑,允许的话,文本字段会失去first
responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
// 文本框失去first
responder 时,执行
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
}
// 指明是否允许根据用户请求清除内容
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
return YES;
}
// 文本框的文本,是否能被修改
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string{
return YES;
}
相关文章推荐
- 面向对象的设计模式(二),Builder模式
- UITableviewCell 重用内存
- 字符串中统计单词个数
- C#中三层架构UI、BLL、DAL、Model实际操作
- zoj 3820 Building Fire Stations(树上乱搞)
- StringBuilder使用小结
- 系统零件
- UITextField属性大全
- EasyUI+Ajax+Json+一般处理程序实现数据的前台与后台的交互
- 152,UIView的常用属性
- UIPickerView
- 【IOS学习笔记】为UICollectionView设置自适应屏幕宽度以及点击效果
- UICollectionView \ UICollectionViewController
- Android 应用程序窗口显示状态操作(requestWindowFeature()的应用)
- WPF,布局,Menu,MenuItem,DockPanel,Grid,DockPanel.Dock='',ToolBar,Content,Image,Uri
- Android GUI 之编辑框(EditText)与监视器
- GUI(概述和布局)
- 34.UIImage — 把多张图片合成一张图
- ios uicollectionview
- 33.使用UIGraphicsGetCurrentContext()重绘图像