The protocol you implement to interact with the text input system and enable features such as autocorrection and multistage text input in documents.
- iOS 8.0+
- tvOS 9.0+
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—that is, 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.
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.
(Multistage text input is required when the language is ideographic and the keyboard is phonetic.)
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-conforming document classes must create custom subclasses of these classes. A UITextPosition object represents a position in a text container. A
UITextRangeobject, which encapsulates beginning and ending
UITextPositionobjects, represents a range of characters in the text container.
UITextInputStringTokenizerclass—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.
UITextInputDelegateprotocol—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.
UIKeyInputprotocol—Implemented to acquire the capabilities of text entry and deletion at an insertion point.
UITextInput protocol also inherits the
UITextInputTraits protocol, and thus the ability to customize the keyboard and its behaviors.
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.