<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextInput",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInput"
  },
  "title" : "UITextInput"
}
-->

# UITextInput

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

```
@MainActor protocol UITextInput : UIKeyInput
```

## Overview

Objects that adopt the [`UITextInput`](/documentation/UIKit/UITextInput) protocol maintain information about text input and provide that information to the text input system on demand. A [`UITextInput`](/documentation/UIKit/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`](/documentation/UIKit/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`](/documentation/UIKit/UITextInput) protocol works with other classes and protocols to integrate text-processing apps with the text input system:

- [`UITextPosition`](/documentation/UIKit/UITextPosition) and [`UITextRange`](/documentation/UIKit/UITextRange) classes: All [`UITextInput`](/documentation/UIKit/UITextInput)-conforming document classes must create custom subclasses of these classes. A [`UITextPosition`](/documentation/UIKit/UITextPosition) object represents a position in a text container. A [`UITextRange`](/documentation/UIKit/UITextRange) object, which encapsulates beginning and ending [`UITextPosition`](/documentation/UIKit/UITextPosition) objects, represents a range of characters in the text container.
- [`UITextInputTokenizer`](/documentation/UIKit/UITextInputTokenizer) protocol and [`UITextInputStringTokenizer`](/documentation/UIKit/UITextInputStringTokenizer) class: The [`UITextInputTokenizer`](/documentation/UIKit/UITextInputTokenizer) protocol defines an interface for tokenizing input text. The [`UITextInputStringTokenizer`](/documentation/UIKit/UITextInputStringTokenizer) class is a default implementation of this protocol.
- [`UITextInputDelegate`](/documentation/UIKit/UITextInputDelegate) protocol: The text input system automatically assigns its own text input delegate (which conforms to this protocol) to the [`UITextInput`](/documentation/UIKit/UITextInput)-conforming document object. This text input delegate allows document objects to inform the input system of changes in text and selection.
- [`UIKeyInput`](/documentation/UIKit/UIKeyInput) protocol: Implement this protocol to allow text entry and deletion at an insertion point.

### Customize keyboard behavior

The [`UITextInput`](/documentation/UIKit/UITextInput) protocol also inherits the [`UITextInputTraits`](/documentation/UIKit/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`](/documentation/UIKit/UITextInput) protocol allow your app to respond to the completion of dictation. You can use an object of the [`UIDictationPhrase`](/documentation/UIKit/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

[`inputDelegate`](/documentation/UIKit/UITextInput/inputDelegate)

An input delegate that receives a notification when text changes or when the selection changes.

[`UITextInputDelegate`](/documentation/UIKit/UITextInputDelegate)

An intermediary between a document and the text input system.

### Replacing and returning text

[`-  textInRange:`](/documentation/UIKit/UITextInput/text(in:))

Returns the text in the specified range.

[`-  replaceRange:withText:`](/documentation/UIKit/UITextInput/replace(_:withText:))

Replaces the text in a document that is in the specified range.

[`-  shouldChangeTextInRange:replacementText:`](/documentation/UIKit/UITextInput/shouldChangeText(in:replacementText:))

Asks whether to replace the text in the specified range.

### Working with marked and selected text

[`selectedTextRange`](/documentation/UIKit/UITextInput/selectedTextRange)

The range of selected text in a document.

[`markedTextRange`](/documentation/UIKit/UITextInput/markedTextRange)

The range of currently marked text in a document.

[`markedTextStyle`](/documentation/UIKit/UITextInput/markedTextStyle)

A dictionary of attributes that describes how to draw marked text.

[`-  setMarkedText:selectedRange:`](/documentation/UIKit/UITextInput/setMarkedText(_:selectedRange:))

Inserts the provided text and marks it to indicate that it is part of an active input session.

[`-  setAttributedMarkedText:selectedRange:`](/documentation/UIKit/UITextInput/setAttributedMarkedText(_:selectedRange:))

Inserts the provided styled text and marks it to indicate that it is part of an active input session.

[`-  unmarkText`](/documentation/UIKit/UITextInput/unmarkText())

Unmarks the currently marked text.

[`selectionAffinity`](/documentation/UIKit/UITextInput/selectionAffinity)

The desired location for the insertion point.

### Computing text ranges and text positions

[`-  textRangeFromPosition:toPosition:`](/documentation/UIKit/UITextInput/textRange(from:to:))

Returns the range between two text positions.

[`-  positionFromPosition:offset:`](/documentation/UIKit/UITextInput/position(from:offset:))

Returns the text position at a specified offset from another text position.

[`-  positionFromPosition:inDirection:offset:`](/documentation/UIKit/UITextInput/position(from:in:offset:))

Returns the text position at a specified offset in a specified direction from another text position.

[`beginningOfDocument`](/documentation/UIKit/UITextInput/beginningOfDocument)

The text position for the beginning of a document.

[`endOfDocument`](/documentation/UIKit/UITextInput/endOfDocument)

The text position for the end of a document.

### Evaluating text positions

[`-  comparePosition:toPosition:`](/documentation/UIKit/UITextInput/compare(_:to:))

Returns how one text position compares to another text position.

[`-  offsetFromPosition:toPosition:`](/documentation/UIKit/UITextInput/offset(from:to:))

Returns the number of UTF-16 characters between one text position and another text position.

### Making the view non-editable

[`editable`](/documentation/UIKit/UITextInput/isEditable)

A Boolean value that indicates whether the text view contains editable text.

### Determining layout and writing direction

[`-  positionWithinRange:farthestInDirection:`](/documentation/UIKit/UITextInput/position(within:farthestIn:))

Returns the text position that is at the farthest extent in a specified layout direction within a range of text.

[`-  characterRangeByExtendingPosition:inDirection:`](/documentation/UIKit/UITextInput/characterRange(byExtending:in:))

Returns a text range from a specified text position to its farthest extent in a certain direction of layout.

[`-  baseWritingDirectionForPosition:inDirection:`](/documentation/UIKit/UITextInput/baseWritingDirection(for:in:))

Returns the base writing direction for a position in the text going in a certain direction.

[`-  setBaseWritingDirection:forRange:`](/documentation/UIKit/UITextInput/setBaseWritingDirection(_:for:))

Sets the base writing direction for a specified range of text in a document.

### Working with geometry and hit-testing

[`-  firstRectForRange:`](/documentation/UIKit/UITextInput/firstRect(for:))

Returns the first rectangle that encloses a range of text in a document.

[`-  closestPositionToPoint:`](/documentation/UIKit/UITextInput/closestPosition(to:))

Returns the position in a document that is closest to a specified point.

[`-  selectionRectsForRange:`](/documentation/UIKit/UITextInput/selectionRects(for:))

Returns an array of selection rects corresponding to the range of text.

[`-  closestPositionToPoint:withinRange:`](/documentation/UIKit/UITextInput/closestPosition(to:within:))

Returns the position in a document that is closest to a specified point in a specified range.

[`-  characterRangeAtPoint:`](/documentation/UIKit/UITextInput/characterRange(at:))

Returns the character or range of characters that is at a specified point in a document.

### Providing the caret layout information

[`-  caretRectForPosition:`](/documentation/UIKit/UITextInput/caretRect(for:))

Returns a rectangle to draw the caret at a specified insertion point.

[`-  caretTransformForPosition:`](/documentation/UIKit/UITextInput/caretTransform(for:))

Returns the transform to apply to the caret prior to drawing.

### Tokenizing input text

[`tokenizer`](/documentation/UIKit/UITextInput/tokenizer)

An input tokenizer that provides information about the granularity of text units.

[`UITextInputTokenizer`](/documentation/UIKit/UITextInputTokenizer)

A tokenizer, which is an object that allows the text input system to evaluate text units of different granularities.

### Managing the floating cursor

[`-  beginFloatingCursorAtPoint:`](/documentation/UIKit/UITextInput/beginFloatingCursor(at:))

Tells the object when the gesture that the system uses to manipulate the cursor begins.

[`-  updateFloatingCursorAtPoint:`](/documentation/UIKit/UITextInput/updateFloatingCursor(at:))

Tells the object that the floating cursor moved to a new location.

[`-  endFloatingCursor`](/documentation/UIKit/UITextInput/endFloatingCursor())

Tells the object when the gesture that the system uses to manipulate the cursor ends.

### Using dictation

[`-  dictationRecordingDidEnd`](/documentation/UIKit/UITextInput/dictationRecordingDidEnd())

Tells the object when there is a pending dictation result.

[`-  dictationRecognitionFailed`](/documentation/UIKit/UITextInput/dictationRecognitionFailed())

Tells the object when dictation ends, but recognition fails.

[`-  insertDictationResult:`](/documentation/UIKit/UITextInput/insertDictationResult(_:))

Tells the object when there is more than one interpretation of a spoken phrase in a dictation result.

[`insertDictationResultPlaceholder`](/documentation/UIKit/UITextInput/insertDictationResultPlaceholder)

Asks for the placeholder object to use while generating dictation results.

[`-  frameForDictationResultPlaceholder:`](/documentation/UIKit/UITextInput/frame(forDictationResultPlaceholder:))

Asks for the rectangle for displaying the dictation placeholder animation.

[`-  removeDictationResultPlaceholder:willInsertResult:`](/documentation/UIKit/UITextInput/removeDictationResultPlaceholder(_:willInsertResult:))

Tells the view that the specified placeholder object is unnecessary.

### Managing placeholders

[`-  insertTextPlaceholderWithSize:`](/documentation/UIKit/UITextInput/insertTextPlaceholder(with:))

Inserts a placeholder object to reserve visual space during text input.

[`-  removeTextPlaceholder:`](/documentation/UIKit/UITextInput/remove(_:))

Removes a placeholder object from the text input view.

[`UITextPlaceholder`](/documentation/UIKit/UITextPlaceholder)

A placeholder object that reserves visual space in a text input view.

### Managing the edit menu

[`-  editMenuForTextRange:suggestedActions:`](/documentation/UIKit/UITextInput/editMenu(for:suggestedActions:))

Asks for the menu to display for the given text range and actions the system provides.

[`-  willPresentEditMenuWithAnimator:`](/documentation/UIKit/UITextInput/willPresentEditMenu(animator:))

Tells the object when the system is about to present an edit menu with an animator.

[`-  willDismissEditMenuWithAnimator:`](/documentation/UIKit/UITextInput/willDismissEditMenu(animator:))

Tells the object when the system is about to dismiss an edit menu with an animator.

### Supporting text-phrase alternatives

[`-  insertText:alternatives:style:`](/documentation/UIKit/UITextInput/insertText(_:alternatives:style:))

[`UITextAlternativeStyle`](/documentation/UIKit/UITextAlternativeStyle)

A constant that determines if the system highlights alternative phrases during text input.

### Inserting a Smart Reply suggestion

[`-  insertInputSuggestion:`](/documentation/UIKit/UITextInput/insert(_:))

Inserts the user or system’s input suggestion into the document.

### Supporting adaptive images

[`supportsAdaptiveImageGlyph`](/documentation/UIKit/UITextInput/supportsAdaptiveImageGlyph)

A Boolean value that indicates whether the document supports adaptive images in the input.

[`-  insertAdaptiveImageGlyph:replacementRange:`](/documentation/UIKit/UITextInput/insert(_:replacementRange:))

Inserts an adaptive image into the text at the specifed location.

### Returning text-styling information

[`-  textStylingAtPosition:inDirection:`](/documentation/UIKit/UITextInput/textStyling(at:in:))

Returns a dictionary with properties that specify how to style the text at a certain location in a document.

### Reconciling text position and character offset

[`-  positionWithinRange:atCharacterOffset:`](/documentation/UIKit/UITextInput/position(within:atCharacterOffset:))

Returns the position within a range of a document’s text that corresponds to the character offset from the start of that range.

[`-  characterOffsetOfPosition:withinRange:`](/documentation/UIKit/UITextInput/characterOffset(of:within:))

Returns the character offset of a position in a document’s text that falls within a specified range.

### Returning the text input view

[`textInputView`](/documentation/UIKit/UITextInput/textInputView)

An affiliated view that provides a coordinate system for all geometric values in the protocol.

### Constants

[`UITextDirection`](/documentation/UIKit/UITextDirection)

The direction of the text.

[`UITextStorageDirection`](/documentation/UIKit/UITextStorageDirection)

The direction of text storage.

[`UITextLayoutDirection`](/documentation/UIKit/UITextLayoutDirection)

The direction of text layout.

### Deprecated

[`UITextWritingDirection`](/documentation/UIKit/UITextWritingDirection)

The writing direction of the text for the language.

[Style dictionary keys](/documentation/UIKit/style-dictionary-keys)

A dictionary that contains properties that define text style characteristics.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`UITextInputTraits`](/documentation/UIKit/UITextInputTraits)

[`UIKeyInput`](/documentation/UIKit/UIKeyInput)

### Conforming Types

[`UISearchTextField`](/documentation/UIKit/UISearchTextField)

[`UITextView`](/documentation/UIKit/UITextView)

[`UITextField`](/documentation/UIKit/UITextField)

### Inherited By

[`UITextDraggable`](/documentation/UIKit/UITextDraggable)

[`UITextDroppable`](/documentation/UIKit/UITextDroppable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)