UITextField详解
来源:互联网 发布:nginx iis 代理服务器 编辑:程序博客网 时间:2024/04/30 09:38
一 属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
UITextField * myTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 50)];
myTextField.backgroundColor = [UIColor clearColor];
//简单设置textField的边缘样式
myTextField.borderStyle = UITextBorderStyleRoundedRect;
//占位显示的内容(水印)
myTextField.placeholder = @
"请输入姓名"
;
//对齐模式
myTextField.textAlignment =
NSTextAlignmentLeft
;
//显示清除按钮的模式
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
// 设置背景图
// myTextField.disabledBackground
// 每次输入字符变成点.常用于密码输入
// myTextField.secureTextEntry = YES;
//再次编辑就清空
// text.clearsOnBeginEditing = YES;
//设置键盘的样式
// text.keyboardType = UIKeyboardTypeNumberPad;
//首字母是否大写
// text.autocapitalizationType = UITextAutocapitalizationTypeNone;
//return键变成什么键
// text.returnKeyType =UIReturnKeyDone;
//键盘外观
// textView.keyboardAppearance=UIKeyboardAppearanceDefault;
//按return键键盘往下收
// becomeFirstResponder
// UIView* view1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,40,0)];
// UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"music.png"]];
// imageView.frame = CGRectMake(0,0,40,40);
// UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
// imageView.image = [UIImage imageNamed:@"music.png"];
//左视图,视图可以是UIView下的任意视图.
// myTextField.leftView = imageView;
//左视图的显示模式
// myTextField.leftViewMode = UITextFieldViewModeAlways;
//右视图
// myTextField.rightView
//右视图显示模式
// myTextField.rightViewMode
二 代理方法
遵守TextField代理后.myTextField.delegate = self;
才能使用它的代理方法;在此就不多做说明.
三 TextField的重绘
除了UITextField对象的风格选项,你还可以定制化UITextField对象,为他添加许多不同的重写方法,来改变文本字段的显示行为。这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围。以下方法都可以重写。(需要创建一个类,继承自UITextField.来重写这些方法).
– textRectForBounds: //重写来重置文字区域
– drawTextInRect: //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– placeholderRectForBounds: //重写来重置占位符区域
– drawPlaceholderInRect: //重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– borderRectForBounds: //重写来重置边缘区域
– editingRectForBounds: //重写来重置编辑区域
– clearButtonRectForBounds: //重写来重置clearButton位置,改变size可能导致button的图片失真
– leftViewRectForBounds:
– rightViewRectForBounds:
在实际开发中,通常重写leftViewRectForBounds方法.并设置leftView,leftViewMode属性,来实现避免输入的内容顶格显示的问题.
原文:http://www.cnblogs.com/xclidongbo/p/4070199.html
0 0
- UITextField详解
- UITextField 详解
- UITextField 详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField 详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField详解
- UITextField 详解
- UITextField详解
- UITextField 详解
- Editplus 当前行高亮技巧
- MongoDB 安全
- Android开发学习笔记二Android Studio
- 使用su后如何返回原来的用户
- 博弈
- UITextField详解
- 关于iOS7 上下黑条解决办法
- Mysql整数运算NULL值处理注意点
- JVM 垃圾回收器工作原理及使用实例介绍
- MongoDB 的使用
- JAVA关于线程自己的一些理解
- 树莓派获取主板温度
- 一个用户加入多个组
- eclipse运行maven的jetty插件内存溢出