UIkit框架之UItextfield
1.继承链:UIcontrol:UIview:UIresponder:NSObject
2.成为第一响应者:[text becomeFirstResponder]; //让该文本成为第一响应者
3.使用resignFirstResponder方法可以取消键盘
4.想要显示键盘需要遵守UITextInputTraits协议,遵守这个协议可以获得以下的行为:
(1)显示键盘的类型,比如英文的、中文的、数字的
(2)键盘的自动大小写行为
(3)键盘的自动纠正行为
(4)return类型的显示
5.键盘响应的通知机制:
6.为文本添加按钮:
text.rightView = button; //在文本的右边加上一个按钮
text.rightViewMode = UITextFieldViewModeAlways; //添加按钮显示的格式
7.显示文本清除功能:
text.clearButtonMode = UITextFieldViewModeAlways;
text.clearsOnBeginEditing = YES; //在文本的右边显示清除功能
8.如果想要使用文本的委托功能和管理文本和用户的交互,需要遵守 UITextFieldDelegate协议
9.文本界面属性:
|
Attribute |
Description |
|---|---|
|
Text |
The initial text displayed by the text field. You can specify the text as a plain string or as an attributed string. If you specify an attributed string, Interface Builder provides different options for editing the font, color, and formatting of the string. |
|
Color |
The color of the text field’s text. To set this attribute programmatically, use the |
|
Font |
The font of the text field’s text. To set this attribute programmatically, use the |
|
Alignment |
The alignment of the text field’s text inside the editing area. This option is available only when formatting plain strings. To set this attribute programmatically, use the |
|
Placeholder |
The placeholder text displayed by the text field. When the text field’s string is empty, the text field displays this string instead, formatting the string so as to indicate that it is not the actual text. Typing any text into the text field hides this string. To set this attribute programmatically, use the |
|
Background |
The background image to display when the text field is enabled. This image is displayed behind the rest of the text field’s content. To set this attribute programmatically, use the |
|
Disabled |
The background image to display when the text field is disabled. This image is displayed behind the rest of the text field’s content. To set this attribute programmatically, use the |
|
Border Style |
The visual style for the text field’s border. This attribute defines the visual border, if any, drawn around the editable text region. To set this attribute programatically, use the |
|
Clear Button |
The behavior of the clear button. The clear button is a built-in overlay view that the user taps to delete all of the text in a text field. Use this attribute to define when the clear button appears. To set this attribute programatically, use the |
|
Min Font Size |
The minimum font size for the text field’s text. When the Adjust to Fit option is enabled, the text field automatically varies the font size to ensure maximum legibility of the text. You can use this attribute to specify the smallest font size that your consider appropriate for your text. To set this attribute programatically, use the |
10.键盘界面属性:想了解这些功能的可以看UITextInputTraits协议
|
Attribute |
Description |
|---|---|
|
Capitalization |
The automatic capitalization style to apply to typed text. This attribute determines at what time the Shift key is automatically pressed. You can access the value of this attribute programmatically using the text field’s |
|
Correction |
The autocorrection behavior of the text field. This attribute determines whether autocorrection is enabled or disabled during typing. You can access the value of this attribute programmatically using the text field’s |
|
Spell Checking |
The spell checking behavior of the text field. This attribute determines whether spell checking is enabled or disabled during typing. You can access the value of this attribute programmatically using the text field’s |
|
Keyboard Type |
The style of the text field’s keyboard. This property specifies the type of keyboard displayed when the text field is active. You can access the value of this attribute programmatically using the text field’s |
|
Appearance |
The visual style applied to the text field’s keyboard. Use this property to specify a dark or light keyboard. You can access the value of this attribute programmatically using the text field’s |
|
Return Key |
The type of return key to display on the keyboard. Use this property to configure the text and visual style applied to the keyboard’s return key. You can access the value of this attribute programmatically using the text field’s The return key is disabled by default and becomes enabled only when the user types some text into the text field. To respond to taps in the Return key, implement the |
11.可存取的属性:
(1)text
(2)attributedText
(3)placeholder
(4)attributedPlaceHolder
(5)defaultTextAttributes:应用于文本的默认属性
(6)font
(7)textColor
(8)textAlignment
(9)typingAttribute:提供一个含有文本属性的字典,当用户改变文本的时候就改变文本属性
12.管理文本框文本
(1)adjustsFontSizeToFitWidth:布尔类型,是否让文本的大小适应文本的宽度
(2)minimumFontSize:cgfloat类型,文本框可允许的最小文字大小,,默认值是0
13.管理编辑行为
(1)editing:布尔类型,确认文本当前是否正在编辑状态
(2)clearOnBeginEditing:布尔类型,在重新进行文本编辑的时候是否清除旧的文本
(3)clearsOnInsertion:布尔类型,在插入文本的时候是否代替之前的内容
(4)allowsEditiingTextAttributes:布尔类型,是否允许用户在文本框内编辑文本的属性
14.设置视图背景显示
(1)borderStype: UITextBorderStyle类型,设置边框的风格
(2)background:UIimage类型,设置背景图片
(3)disabledBackground:UIimage类型,当文本不使用的时候就这个来当背景。
(4)clearButtonMode:UITextFieldViewMode类型 ,控制在文本框的标准清除按钮控件
(5)leftView:UIView类型,用一个视图来覆盖文本框左边的区域,和rightview的功能类型
(6)leftViewMode:UITextFieldViewMode类型,控制什么时候左边的覆盖视图出现在文本框
15.可存取的委托:
(1)id< UITextFieldDelegate>类型,可以用来响应一些用户输入的命令或者信息,例如return被按下的时候delegate:
16.重载绘制和位置功能:
(1)- (CGRect)textRectForBounds:(CGRect)bounds:这个方法一般都不会直接使用,返回当你想自定义文本框的rect属性的时通过重载的方法使用。
(2)- (void)drawTextInRect:(CGRect)rect :这个方法一般是用来进行重载的时候来重新定义你想要的文本的rect属性
(3)- (CGRect)placeholderRectForBounds:(CGRect)bounds : 这个方法一般用来进行重载的时候返回重新定义你想要背景文字的rect属性
(4)- (void)drawPlaceholderInRect:(CGRect)rect :绘制背景文字的显示矩形大小
(5)- (CGRect)borderRectForBounds:(CGRect)bounds : 返回接收者的边框矩形
(6)- (CGRect)editingRectForBounds:(CGRect)bounds :返回能够被编辑区域的矩形
(7)- (CGRect)clearButtonRectForBounds:(CGRect)bounds :返回内置清除按钮的绘制矩形,当你想要改变按钮的位置的时候可以重载这个方法
(8)- (CGRect)leftViewRectForBounds:(CGRect)bounds : 返回左边覆盖视图的矩形 ,当你想改变视图的位置的时候可以重载这个方法进行调整
17.代替系统的输入视图:
(1)inputView :当文本成为第一响应者的时候就会显示这个视图,为nil的时候会显示系统的键盘
(2)inputAccessoryView :附加视图,可以为键盘添加附加的工具栏
18.功能辅助:
(1)UITextBorderStyle的类型:
UITextBorderStyleNone:不显示边界
UITextBorderStyleLine:显示一条线作为边界
UITextBorderStyleBezel: 通常应用到数据输入的文本框
UITextBorderStyleRoundedRect:显示圆角矩形的边界
(2)UITextFieldViewMode的类型:
UITextFieldViewModeNever:覆盖视图从来不显示
UITextFieldViewModeWhileEditing:只有当文本框正在编辑的时候才会显示这个覆盖视图
UITextFieldViewModeUnlessEditing:只有当文本框不编辑的时候才会显示这个覆盖视图
UITextFieldViewModeAlways:无论什么时候都会显示这个覆盖视图
(3)UITextFieldTextDidBeginEditingNotification:通知观察者文本已经开始编辑
(4)UITextFieldTextDidChangeNotification:通知观察者文本的内容已经改变
(5)UITextFieldTextDidEndEditingNotification:通知观察着文本的内容已经编辑结束
UIkit框架之UItextfield的更多相关文章
- UIKit框架使用总结--看看你掌握了多少
一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
随机推荐
- python 基础学习(元组,if,for)
1.tuple对象 tuple 元组 有序的列表 tuple一旦创建不能修改 a.定义元组t=('a','b','c')空元素的tuple t=()()既表示tuple 也表示运算符的优先级 所以定义 ...
- IDEA配置maven
步骤:Setting....或Ctrl+Alt+S
- 报错解决:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
大概分析一般使用了注解才会报这方面的错 1.没有在spring的ApplicationContext.xml中开启注解事务 <!-- 开启注解事务 --> <tx:annotatio ...
- ...python の 学习
5.14 ...上次学python 好像是一个月前.. 写点东西记录下叭.. 现在在看李老大写的博客写..可能直接开抄代码... 感觉自己写的总是爬不成功,之前写的爬豆瓣影评的爬虫还是残的... 1. ...
- 数据库与SQL语言
数据库(DB) :长期储存在计算机中.有组织.可共享的数据的集合. 特点:(1)数据按一定的数据模型组织.描述和储存:(2)较小的冗余度:(3)数据独立性较高:(4)易扩展:(5)可共享(不同用户可按 ...
- node.js+WebStorm路径问题
目录路径 :A文件夹下有B.C文件夹和app.js文件.B文件夹下有webserver.js文件等. A B webserver.js ...... C ...... app.js WebStorm配 ...
- [Js]基础知识
一.JavaScript组成 1.ECMAScript 解释器.翻译(提供功能有限,如加减乘除,定义变量.函数等) 几乎没有兼容性问题 2.DOM 有一些兼容性问题 3.BOM(用的少,交互 ...
- Json数据,日期的转换
using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE)) { con.Open(); using (SQLi ...
- Redis系列-存储篇sorted set主要操作函数小结
redis支持有序集合,即sorted set.sorted set在set的基础上,增加了排序属性,是set的升级版.这里简要谈谈sorted set的常用函数: 1)insert a) zadd ...
- JavaScript数字精度上代码。
/**不能超过 9007199254740992 * floatObj 包含加减乘除四个方法,能确保浮点数运算不丢失精度 * * 我们知道计算机编程语言里浮点数计算会存在精度丢失问题(或称舍入误差), ...