UI基础:UITextField
来源:互联网 发布:什么是淘宝店铺维护 编辑:程序博客网 时间:2024/04/29 20:22
UITextField 继承自UIControl,他是在UILabel基础上,对了文本的编辑.可以允许用户输入和编辑文本
UITextField的使用步骤
1.创建控件
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 300, 50)];textField.tag=100;//为textField赋tag,目的是可以通过父视图找到textField
2.设置属性
(1).设置背景
textField.backgroundColor=[UIColor yellowColor];
(2).设置文本框提示文字
textField.placeholder=@"请输入金额";//输入占位符.一旦有内容输入就消失
(3).设置文本
textField.text=@"520$";
(4).设置文本颜色
textField.textColor=[UIColor redColor];
(5).文本对齐方式
textField.textAlignment=NSTextAlignmentCenter;//居中
(6).设置文本框的样式
textField.borderStyle=UITextBorderStyleRoundedRect;//文本框边角圆弧
(7).设置文本框是否能被编辑(默认是YES,可以编辑)
textField.enabled=NO;
(8).当开始输入文本时,是否清空原文本框的内容(默认值是NO)
textField.clearsOnBeginEditing=YES;
(9)设置return的按键样式
textField.returnKeyType=UIReturnKeyGo;
(10)设置弹出键盘的样式
textField.keyboardType=UIKeyboardTypeNumberPad;//弹出数字键盘
(11)设置输入文本框的文字以密码模式显示
textField.secureTextEntry=YES;
(12)自定义弹出视图
UIView *inPutView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 250)];nPutView.backgroundColor=[UIColor cyanColor];textField.inputView=inPutView;[inPutView release];
(13)自定义键盘上方的辅助视图
UIView *accessView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];accessView.backgroundColor=[UIColor cyanColor];textField.inputAccessoryView=accessView;[accessView release];
(14)设置文本框的清理模式
textField.clearButtonMode=UITextFieldViewModeWhileEditing;//当编辑时显示清理按钮
(15)设置文本框的代理
针对某个类的代理(协议)的命名规则:类名+delegate
当一个类的属性遵循了某个协议的属性.它的命名:delegate
delegate的属性语义特性使用assign
在对象(-)方法里,self代表该对象,在类(+)方法,self代表该类
textField.delegate=self;
//总结:要遵循代理(协议),这个类必须是已知类(因为要在遵循代理的类的.m中实现协议方法)
// 添加到父视图
[self.window addSubview:textField];
// 释放所有权
[textField release];self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];return YES;}
#pragma mark -----------UITextFieldDelegate代理方法--------------- (BOOL)textFieldShouldReturn:(UITextField *)textField{//回收键盘 [textField resignFirstResponder]; return YES;}#pragma mark --------不是代理的方法,是点击事件的方法-----------(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITextView *textField=(UITextView *)[self.window viewWithTag:100];//通过tag找到textField [textField resignFirstResponder]; //回收键盘}
文本显示
输入控制
外观控制
0 0
- UI基础:UITextField
- UI基础_UITextView/UITextField
- UI基础控件系列---->UITextField
- UI基础控件(二)-------- UITextField
- UI基础学习之(三):UITextField
- UI-UITextField
- UI UITextField
- iOS-UI-基础控件核心API-UITextField&UIButton
- UI -- UITextField总结
- 13、UITextField-OC+UI
- UI 03 UITextField
- UI - UITextField和UIButton
- UI-UITextField UIButton
- UI控件-UITextField
- UI基本控件---UITextField
- UI UILabel Button UITextField
- **原创**零基础学ios**UI课程01***课堂笔记整理*UIView UILabel UIButton UITextField**
- iOS基础——UI控件之UIView、UITextField、UILabel、UIColor、UIButton、UIImageView
- 光学测量的精度
- Shell常用招式大全之入门篇
- JavaScript学习13:事件绑定
- 优化Linux下的内核TCP参数来提高服务器负载能力
- windows上通过vnc连接虚拟机中linux系统
- UI基础:UITextField
- SQL SERVER的事务未提交与死锁问题。
- C#如何在线程里调用带参数的方法
- 数组
- bitcount using bit method
- [华为机试练习题]32.数字基root
- relatedTarget, fromElement, toElement
- 《数学之美(第二版)》(二)
- FASTDFS PYTHON [-] Error: response size not match, expect: 105, actual: 105 解决