iOS - UITextField简单使用
2013-07-02 08:47
316 查看
一、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;
}
相关文章推荐
- IOS中UITextField和UILabel简单使用
- iOS--UITextField的简单使用
- 【iOS开发】简单UI部分UIButton的创建和UITextField的使用
- iOS学习之Table View的简单使用
- iOS Date Picker控件的简单使用(点击一个input框,弹出)
- iOS菜鸟-使用MapKit和CoreLocation实现简单的导航画线
- iOS 多线程 & 网络 - 4.0 - AFN框架简单使用
- iOS-浅谈runtime运行时机制02-runtime简单使用
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
- phoneGap在iOS上的简单使用:弹出对话框和调用相机
- iOS-UI分析利器--Reveal安装破解以及简单使用
- iOS_第3方类库SDWebImage简单使用
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- iOS学习之——简单的Git使用
- ios简单sqlite使用
- iOS学习之UIPickerView控件的简单使用
- iOS开发 - 百度地图的简单使用
- iOS-CoreImage简单使用
- iOS中UITextField 使用全面解析
- iOS开发的2D绘制--CoreGraphics的简单使用一(画线条)