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 textColor property.

Font

The font of the text field’s text. To set this attribute programmatically, use the fontproperty.

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 textAlignment property.

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 placeholder property.

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 background property.

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 disabledBackground property.

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 borderStyle property.

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 theclearButtonModeproperty.

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 theminimumFontSize property.

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 autocapitalizationTypeproperty.

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 autocorrectionType property.

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 spellCheckingType property.

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 keyboardType property.

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 keyboardAppearance property.

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 returnKeyTypeproperty.

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 textFieldShouldReturn: method in the delegate you assign to the text field.

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)delegateid< UITextFieldDelegate>类型,可以用来响应一些用户输入的命令或者信息,例如return被按下的时候

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的更多相关文章

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  3. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  4. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  5. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  6. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  7. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  8. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  9. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

随机推荐

  1. js 中 continue 与 break 熟练使用

    //break:在循环体中,遇到break,整个循环都结束了,后面的累加操作也不在执行了,并且循环体中,只要遇到break,那么循环体break后面的代码都不在执行了 //continue:在循环体中 ...

  2. IE9以上 CSS文件因Mime类型不匹配而被忽略 其他浏览器及IE8以下显示正常

     什么是Mime类型? MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名 ...

  3. IIS 安装 pydio

    Introduction In this how-to, we’ll see the installation of Pydio (Put Your Data In Orbit), which is ...

  4. hibernate annotation注解方式来处理映射关系

    在hibernate中,通常配置对象关系映射关系有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,熟话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,我在试了这两种方式 ...

  5. hduoj-----(2896)病毒侵袭(ac自动机)

    病毒侵袭 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. java之如何实现调用启动一个可执行文件,exe

    /* * 运行可执行文件:.exe * 当要执行一个本地机器上的可执行文件时, * 可以使用java.lang包中的Runtime类,首先使用Runtime类,首先 * 使用Runtime类声明一个对 ...

  7. Path Sum [LeetCode]

    Problem Description: http://oj.leetcode.com/problems/path-sum/ Pretty easy. /** * Definition for bin ...

  8. Multiply Strings [LeetCode]

    Problem Description http://oj.leetcode.com/problems/multiply-strings/ Basic idea is to multiply two ...

  9. html5 <input> placeholder 属性

    带有 placeholder 文本的搜索字段: <form action="demo_form.asp" method="get"> <inp ...

  10. CPU厂商

    1·Intel公司 Intel是生产CPU的老大哥,它占有大约80%的市场份额,Intel生产的CPU就成了事实上的x86CPU技术规范和标准.最新的酷睿2成为CPU的首选. 2·AMD公司 除了In ...