iOS开发之 UITextField
2015-09-11 19:59
513 查看
一、UITextField
文本输入的控件
UITextField -文本输入控件,它就和我们登录qq上输入账号和密码的输入框是一样的
![](http://img.blog.csdn.net/20150911200105785?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
1、初始化uitextField
UITextField *pewTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 40)];
给pewTextField
设置背景图片
1⃣️. pewTextField.background = [UIImage imageNamed:@“F23C46DE-8B36-4048-8365-3FB4643922E9”];//设置不禁用时的背景
2⃣️.pewTextField.disabledBackground = [UIImage imageNamed:@“D205413E-C6AF-484E-A586-4982B97F6D3F"];//设置禁用时的背景
2. enabled
是否禁用控件 默认是yes,没有禁用
pewTextField.enabled = YES;
3.pewTextField
自身的属性
1⃣️pewTextField.borderStyle = UITextBorderStyleRoundedRect;//设置边框的类型
2⃣️pewTextField.placeholder = @"请输入密码";//提示的文字,当编辑时
消失
3⃣️pewTextField.textAlignment = NSTextAlignmentCenter;//显示的文本居中
4⃣️pewTextField.secureTextEntry = YES;//设置成
不是明文显示
5⃣️pewTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;//设置键盘输入样式
6⃣️pewTextField.keyboardAppearance = UIKeyboardAppearanceDark;//设置键盘显示的样式
7⃣️pewTextField.returnKeyType = UIReturnKeyDefault;//设置返回键的样式
8⃣️pewTextField.clearButtonMode = UITextFieldViewModeWhileEditing;//设置清除按钮
什么时候出现
4.在TextField 左边或者右边添加一个视图
UIView *left = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 40)];
left.layer.cornerRadius = 4;//设置拐角
left.backgroundColor = [UIColor redColor];
pewTextField.leftView = left;//把需要放到TextField
的左边或者右边的视图
赋值给TextField的左边或者右边
pewTextField.leftViewMode = UITextFieldViewModeAlways;//还需要设置左边或者右边视图的样式
5.代理
// 代理
:让别人帮忙做某件事儿 自己在本类中
实现不了得功能 让其他类帮咱们实现
// 咱们需要让pewTextField
帮咱们
获得输入完成后的字符串
// 如果要使用代理
需添加 代理的协议
对于TextField,我们在使用的时候,一般会用到它的代理方法,正如我们得判断自己是否开始在这个输入框输入东西,或者是我们已经在这个输入框输入完毕了呢 ?我们就使用代理,在使用代理的时候,我们导入代理,并且得给TextField挂上代理
如下:
我们还得给 TextField 挂上代理,一般在初始化TextField的地方挂上
在这里我们就不把TextField 的代理全部列举出来了,我们看看TextField常用的两个代理方法
文本输入的控件
UITextField -文本输入控件,它就和我们登录qq上输入账号和密码的输入框是一样的
1、初始化uitextField
UITextField *pewTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 40)];
给pewTextField
设置背景图片
1⃣️. pewTextField.background = [UIImage imageNamed:@“F23C46DE-8B36-4048-8365-3FB4643922E9”];//设置不禁用时的背景
2⃣️.pewTextField.disabledBackground = [UIImage imageNamed:@“D205413E-C6AF-484E-A586-4982B97F6D3F"];//设置禁用时的背景
2. enabled
是否禁用控件 默认是yes,没有禁用
pewTextField.enabled = YES;
3.pewTextField
自身的属性
1⃣️pewTextField.borderStyle = UITextBorderStyleRoundedRect;//设置边框的类型
2⃣️pewTextField.placeholder = @"请输入密码";//提示的文字,当编辑时
消失
3⃣️pewTextField.textAlignment = NSTextAlignmentCenter;//显示的文本居中
4⃣️pewTextField.secureTextEntry = YES;//设置成
不是明文显示
5⃣️pewTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;//设置键盘输入样式
6⃣️pewTextField.keyboardAppearance = UIKeyboardAppearanceDark;//设置键盘显示的样式
7⃣️pewTextField.returnKeyType = UIReturnKeyDefault;//设置返回键的样式
8⃣️pewTextField.clearButtonMode = UITextFieldViewModeWhileEditing;//设置清除按钮
什么时候出现
4.在TextField 左边或者右边添加一个视图
UIView *left = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 40)];
left.layer.cornerRadius = 4;//设置拐角
left.backgroundColor = [UIColor redColor];
pewTextField.leftView = left;//把需要放到TextField
的左边或者右边的视图
赋值给TextField的左边或者右边
pewTextField.leftViewMode = UITextFieldViewModeAlways;//还需要设置左边或者右边视图的样式
5.代理
// 代理
:让别人帮忙做某件事儿 自己在本类中
实现不了得功能 让其他类帮咱们实现
// 咱们需要让pewTextField
帮咱们
获得输入完成后的字符串
// 如果要使用代理
需添加 代理的协议
对于TextField,我们在使用的时候,一般会用到它的代理方法,正如我们得判断自己是否开始在这个输入框输入东西,或者是我们已经在这个输入框输入完毕了呢 ?我们就使用代理,在使用代理的时候,我们导入代理,并且得给TextField挂上代理
如下:
@interface ViewController : UIViewController<UITextFieldDelegate>
我们还得给 TextField 挂上代理,一般在初始化TextField的地方挂上
pewTextField.delegate = self;//如果代理方法不执行,先检查是否挂上代理
在这里我们就不把TextField 的代理全部列举出来了,我们看看TextField常用的两个代理方法
//开始编辑的时候使用 - (void)textFieldDidBeginEditing:(UITextField *)textField { NSLog(@"已经开始编辑"); } //编辑结束的时候调用 - (void)textFieldDidEndEditing:(UITextField *)textField { NSLog(@"%@",textField.text); }
相关文章推荐
- Storyboard中segue使用总结
- UE4ShaderPluginDemo
- UITableView Cell上添加按钮后改变选择状态
- iOS开发之 UILabel,UIButton
- 解决错误 Target runtime com.genuitec.runtime.generic.jee60 is not defined.
- iOS开发之 window , UIView
- iOS动态计算UIScrollView的contentSize示例(页面由Label组成)
- UIActivityIndicatorView的使用
- iOS开发-------简单通讯录(UITableView和CoreData的应用)
- HDU 5412——CRB and Queries——————【线段树套Treap(并没有AC)】
- easyui text如何 绑定 鼠标离开时间 及blur 事件
- [Android UI开发] 仿微信/支付宝的密码输入框效果:GridPasswordView
- [Android UI开发] 固定在ScrollView顶部的View,类似于新浪微博的评论列表的顶部
- [Android UI开发] Android常用工具类
- hdoj 1242 Rescue 【bfs】
- UITableView 分页显示、加载更多,数据源远程数据,解析JSON,以及iOS☞Category
- IOS开发UI展示之UITableView ──分页加载更多
- android Bluetooth程序设计
- UE4使用第三方库
- 将输出绑定到UITextView