Contents

UITextInput

A set of methods for interacting with the text input system and enabling features in documents.

Declaration

@MainActor protocol UITextInput : UIKeyInput

Mentioned in

Overview

Objects that adopt the UITextInput protocol maintain information about text input and provide that information to the text input system on demand. A UITextInput object interacts with the text input system by:

  • Reporting text positions and text ranges

  • Responding to queries layout and writing direction

  • Performing hit-testing — returning text positions and ranges for a specific point

  • Providing the system with rectangles for highlighting ranges of text and drawing the caret, a glyph that represents the insertion point during text entry

In addition, a UITextInput object maintains ranges for selected text and marked text. Marked text, a part of multistage text input, represents provisionally inserted text that the user has yet to confirm. The range of marked text always contains a range of selected text, which might be a range of characters or the caret. Multistage text input is a requirement when the language is ideographic and the keyboard is phonetic.

Integrate with the text input system

The UITextInput protocol works with other classes and protocols to integrate text-processing apps with the text input system:

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.

UITextInputTokenizer protocol and UITextInputStringTokenizer class

The UITextInputTokenizer protocol defines an interface for tokenizing input text. The UITextInputStringTokenizer class is a default implementation of this protocol.

UITextInputDelegate protocol

The text input system automatically assigns its own text input delegate (which conforms to this protocol) to the UITextInput-conforming document object. This text input delegate allows document objects to inform the input system of changes in text and selection.

UIKeyInput protocol

Implement this protocol to allow text entry and deletion at an insertion point.

Customize keyboard behavior

The UITextInput protocol also inherits the UITextInputTraits protocol, which provides customization of 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. You can use an object of the UIDictationPhrase class to obtain a string that represents a phrase the user dictates. In the case of ambiguous dictation results, a dictation phrase object provides an array that contains alternative strings.

Topics

Handling text input

Replacing and returning text

Working with marked and selected text

Computing text ranges and text positions

Evaluating text positions

Making the view non-editable

Determining layout and writing direction

Working with geometry and hit-testing

Providing the caret layout information

Tokenizing input text

Managing the floating cursor

Using dictation

Managing placeholders

Managing the edit menu

Supporting text-phrase alternatives

Inserting a Smart Reply suggestion

Supporting adaptive images

Returning text-styling information

Reconciling text position and character offset

Returning the text input view

Constants

Deprecated

Instance Properties

Instance Methods

See Also

Text input