uitextinput协议参考

UITextInput Protocol Reference
uitextinput协议参考
Conforms to
符合
UIKeyInput
uikeyinput
Framework
框架
/System/Library/Frameworks/UIKit.framework
/系统/图书馆/框架/ uikit.framework
Availability
可用性
Available in iOS 3.2 and later.
在3.2及以后。
Companion guide
伴侣指南
Text, Web, and Editing Programming Guide for iOS
文本,网页,和编辑程序设计指导办公室
Declared in
宣布
UITextInput.h
uitextinput。小时
Overview
概述
Classes that adopt the UITextInput protocol (and conform with inherited protocols) interact with the text input system and thus acquire features such as autocorrection and multistage text input for their documents. (Multistage text input is required when the language is ideographic and the keyboard is phonetic.)
类,采用uitextinput协议(和符合继承协议)互动的文本输入系统,从而获得等功能的自动校正和多级文本输入文件。(多输入文本时需要的是表意与键盘的拼音。)
Note: Here, a document is assumed to be a view capable of displaying and manipulating text.
注:在这里,一个文件被假定为一个视图可以显示和操作文本。
Objects of classes that adopt the UITextInput protocol provide the text input system with text positions and text ranges on demand, answer questions about layout and writing direction, perform hit-testing (returning text positions and ranges for a given point), and provide the system with rectangles that can be used for highlighting ranges of text and drawing the caret. In addition, a UITextInput object maintains ranges for selected text and marked text.
类的对象,采用uitextinput协议提供的文本输入系统与文字的立场和文本范围的需求,回答有关问题,布局和书写方向,执行命中测试(返回文本的位置和范围,对于一个给定的点),并使系统具有矩形可以用于突出显示文本的范围和绘图符号。此外,一个uitextinput对象维护的范围选定文本和标记的文本。
Marked text, which is part of multistage text input, represents provisionally inserted text that the user has yet to confirm. It is styled in a distinctive way. The range of marked text always contains within it a range of selected text, which might be a range of characters or the caret.
标记的文本,其中一部分是多级文本输入,代表临时插入文本,用户还没有确认。它是一种独特的方式。各种标记的文本总是包含在它的一系列选定的文本,这可能是一个范围的字符或符号。
The UITextInput protocol is the center of a constellation of classes and protocols for integrating text-processing applications with the text input system. The other parts of this constellation are the following:
该uitextinput协议的中心是一个星座的类和协议应用整合文本与文本输入系统。其他地区的这个星座如下:
UITextPosition and UITextRange classes—All UITextInput-conforming document classes must create custom subclasses of these classes. A UITextPosition object represents a position in a text container. A UITextRange object, which encapsulates beginning and ending UITextPosition objects, represents a range of characters in the text container.
uitextposition和uitextrange classes-all uitextinput-conforming文档类必须创建自定义的子类。一个uitextposition对象代表一个位置在一个文本容器。一个uitextrange对象,其中包含的开始和结束uitextposition对象,代表一个字符范围的文本容器。
UITextInputTokenizer protocol and UITextInputStringTokeniz er class—The protocol defines an interface for a tokenizer object that enables the text input system to evaluate text units of different granularities. The class is a default implementation of this protocol.
uitextinputtokenizer协议和uitextinputstringtokeniz er即协议定义了一个接口的一个标记生成对象,使得文本输入系统评价文本的单位不同粒度。类的默认此协议的实施。
UITextInputDelegate protocol—The text input system automatically assigns its own text input delegate (which conforms to this protocol) to the UITextInput-conforming document object. Through this text input delegate, a document object informs the text input system of changes in text and selection.
uitextinputdelegate协议文本输入系统自动分配自己的文字输入代表(符合本协议)的uitextinput-conforming文档对象。通过这一文本输入的代表,一个文件对象的通知文本输入系统变化的文字和选择。
UIKeyInput protocol—Implemented to acquire the capabilities of text entry and deletion at an insertion point.
uikeyinput protocol-implemented获得能力的文字录入和删除插入点。
The UITextInput protocol also inherits the UITextInputTraits protocol, and thus the ability to customize the keyboard and its behaviors.
该uitextinput协议也继承了uitextinputtraits协议,从而能够自定义键盘及其行为。
Starting in iOS 5.1, when the user chooses dictation input on a supported device, the system automatically inserts recognized phrases into the current text view. Methods in the UITextInput protocol allow your app to respond to the completion of dictation, as described in “Using Dictation.” You can use an object of the UIDictationPhrase class to obtain a string representing a phrase a user has dictated. In the case of ambiguous dictation results, a dictation phrase object provides an array containing alternative strings.
在5.1,当用户选择听写输入一个支持的设备,系统会自动插入到当前文本观承认短语。方法在uitextinput协议允许你的程序以完成听写,中所描述的“听写”。你可以使用一个对象的uidictationphrase类获取一个字符串代表一个短语用户命令。在模棱两可的情况听写结果,听写词语对象提供一个数组包含替代字符串。
Tasks
任务
Replacing and Returning Text
更换和返回文本
– textInRange:   required method
–textinrange:要求的方法
– replaceRange:withText:   required method
–replacerange:withtext:要求的方法
Working with Marked and Selected Text
与标记和选定的文本
   selectedTextRange   required property
selectedtextrange要求的性能
   markedTextRange   required property
markedtextrange要求的性能
   markedTextStyle   required property
markedtextstyle要求的性能
– setMarkedText:selectedRange:   required method
–setmarkedtext:selectedrange:要求的方法
– unmarkText   required method
–unmarktext要求的方法
   selectionAffinity   property
selectionaffinity财产
Computing Text Ranges and Text Positions
计算文本和文本位置
– textRangeFromPosition:toPosition:   required method
–textrangefromposition:toposition:要求的方法
– positionFromPosition:offset:   required method
–positionfromposition:偏移:要求的方法
– positionFromPosition:inDirection:offset:   required method
–positionfromposition:间接胶印方法:要求:
   beginningOfDocument   required property
beginningofdocument要求的性能
   endOfDocument   required property
endofdocument要求的性能
Evaluating Text Positions
评价文本位置
– comparePosition:toPosition:   required method
–compareposition:toposition:要求的方法
– offsetFromPosition:toPosition:   required method
–offsetfromposition:toposition:要求的方法
Determining Layout and Writing Direction
确定的布局和写作方向
– positionWithinRange:farthestInDirection:
–positionwithinrange:farthestindirection:
– characterRangeByExtendin gPosition:inDirection:   required method
–characterrangebyextendin gposition:间接的:要求的方法
– baseWritingDirectionForP osition:inDirection:   required method
–basewritingdirectionforp osition:间接的:要求的方法
– setBaseWritingDirection:forRange:   required method
–setbasewritingdirection:forrange:要求的方法
Geometry and Hit-Testing Methods
几何和命中测试方法
– firstRectForRange:   required method
–firstrectforrange:要求的方法
– caretRectForPosition:   required method
–caretrectforposition:要求的方法
– closestPositionToPoint:   required method
–closestpositiontopoint:要求的方法
– closestPositionToPoint:withinRange:   required method
–closestpositiontopoint:withinrange:要求的方法
– characterRangeAtPoint:   required method
–characterrangeatpoint:要求的方法
Text Input Delegate and Text Input Tokenizer
文本输入代表和文本输入标记生成器
   inputDelegate   required property
inputdelegate要求的性能
   tokenizer   required property
标记生成所需的性能
Using Dictation
利用听写
– dictationRecordingDidEnd
–dictationrecordingdidend
– dictationRecognitionFail ed
–dictationrecognitionfail ed
– insertDictationResult:
–insertdictationresult:
Returning Text Styling Information
返回文本样式信息
– textStylingAtPosition:inDirection:
–textstylingatposition:间接:
Recon
侦察
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInput_Protocol/Reference/Reference.html
:/ /开发。苹果。”/图书馆/组织/ #文件/ uikit /参考/ uitextinput_protocol /参考/ reference.html
百度在线翻译
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用UITextInput来限制字符输入个数,你可以通过以下步骤实现: 1. 在你的视图或控件中实现UITextInput协议。 2. 添加一个实例变量来跟踪当前的文本字符数量。 3. 在插入文本的方法中,检查插入的文本是否会超过限制的字符个数。如果超过限制,可以选择不插入或截断文本。 4. 在删除文本的方法中,更新当前的文本字符数量。 下面是一个简单的示例代码,演示了如何使用UITextInput来限制字符输入个数: ```swift class MyTextView: UIView, UITextInput { private var text = "" private let characterLimit = 10 // 实现UITextInput协议的方法 // 插入文本 func insertText(_ text: String) { let newLength = self.text.count + text.count if newLength <= characterLimit { self.text.append(contentsOf: text) } } // 删除文本 func deleteBackward() { if !self.text.isEmpty { self.text.removeLast() } } // 获取文本范围 func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange? { // 实现文本范围方法 return nil } // 获取光标位置 func position(from position: UITextPosition, offset: Int) -> UITextPosition? { // 实现光标位置方法 return nil } // 其他UITextInput协议方法... } ``` 在上面的示例代码中,我们在MyTextView类中实现了UITextInput协议,并添加了一个实例变量text来保存当前的文本。在insertText方法中,我们检查要插入的文本是否会超过字符限制,如果没有超过,则将其追加到当前的文本中。在deleteBackward方法中,我们删除最后一个字符。你可以根据需要自定义其他UITextInput协议的方法。 请注意,这只是一个简单的示例,你可以根据你的实际需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值