---
title: UITextInput
framework: uikit
role: symbol
role_heading: Protocol
path: uikit/uitextinput
---

# UITextInput

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

## Declaration

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

## Mentioned in

Adopting system selection UI in custom text views Adopting Smart Reply in your messaging or email app

## Overview

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: 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

- [inputDelegate](uikit/uitextinput/inputdelegate.md)
- [UITextInputDelegate](uikit/uitextinputdelegate.md)

### Replacing and returning text

- [text(in:)](uikit/uitextinput/text(in:).md)
- [replace(_:withText:)](uikit/uitextinput/replace(_:withtext:).md)
- [shouldChangeText(in:replacementText:)](uikit/uitextinput/shouldchangetext(in:replacementtext:).md)

### Working with marked and selected text

- [selectedTextRange](uikit/uitextinput/selectedtextrange.md)
- [markedTextRange](uikit/uitextinput/markedtextrange.md)
- [markedTextStyle](uikit/uitextinput/markedtextstyle.md)
- [setMarkedText(_:selectedRange:)](uikit/uitextinput/setmarkedtext(_:selectedrange:).md)
- [setAttributedMarkedText(_:selectedRange:)](uikit/uitextinput/setattributedmarkedtext(_:selectedrange:).md)
- [unmarkText()](uikit/uitextinput/unmarktext().md)
- [selectionAffinity](uikit/uitextinput/selectionaffinity.md)

### Computing text ranges and text positions

- [textRange(from:to:)](uikit/uitextinput/textrange(from:to:).md)
- [position(from:offset:)](uikit/uitextinput/position(from:offset:).md)
- [position(from:in:offset:)](uikit/uitextinput/position(from:in:offset:).md)
- [beginningOfDocument](uikit/uitextinput/beginningofdocument.md)
- [endOfDocument](uikit/uitextinput/endofdocument.md)

### Evaluating text positions

- [compare(_:to:)](uikit/uitextinput/compare(_:to:).md)
- [offset(from:to:)](uikit/uitextinput/offset(from:to:).md)

### Making the view non-editable

- [isEditable](uikit/uitextinput/iseditable.md)

### Determining layout and writing direction

- [position(within:farthestIn:)](uikit/uitextinput/position(within:farthestin:).md)
- [characterRange(byExtending:in:)](uikit/uitextinput/characterrange(byextending:in:).md)
- [baseWritingDirection(for:in:)](uikit/uitextinput/basewritingdirection(for:in:).md)
- [setBaseWritingDirection(_:for:)](uikit/uitextinput/setbasewritingdirection(_:for:).md)

### Working with geometry and hit-testing

- [firstRect(for:)](uikit/uitextinput/firstrect(for:).md)
- [closestPosition(to:)](uikit/uitextinput/closestposition(to:).md)
- [selectionRects(for:)](uikit/uitextinput/selectionrects(for:).md)
- [closestPosition(to:within:)](uikit/uitextinput/closestposition(to:within:).md)
- [characterRange(at:)](uikit/uitextinput/characterrange(at:).md)

### Providing the caret layout information

- [caretRect(for:)](uikit/uitextinput/caretrect(for:).md)
- [caretTransform(for:)](uikit/uitextinput/carettransform(for:).md)

### Tokenizing input text

- [tokenizer](uikit/uitextinput/tokenizer.md)
- [UITextInputTokenizer](uikit/uitextinputtokenizer.md)

### Managing the floating cursor

- [beginFloatingCursor(at:)](uikit/uitextinput/beginfloatingcursor(at:).md)
- [updateFloatingCursor(at:)](uikit/uitextinput/updatefloatingcursor(at:).md)
- [endFloatingCursor()](uikit/uitextinput/endfloatingcursor().md)

### Using dictation

- [dictationRecordingDidEnd()](uikit/uitextinput/dictationrecordingdidend().md)
- [dictationRecognitionFailed()](uikit/uitextinput/dictationrecognitionfailed().md)
- [insertDictationResult(_:)](uikit/uitextinput/insertdictationresult(_:).md)
- [insertDictationResultPlaceholder](uikit/uitextinput/insertdictationresultplaceholder.md)
- [frame(forDictationResultPlaceholder:)](uikit/uitextinput/frame(fordictationresultplaceholder:).md)
- [removeDictationResultPlaceholder(_:willInsertResult:)](uikit/uitextinput/removedictationresultplaceholder(_:willinsertresult:).md)

### Managing placeholders

- [insertTextPlaceholder(with:)](uikit/uitextinput/inserttextplaceholder(with:).md)
- [remove(_:)](uikit/uitextinput/remove(_:).md)
- [UITextPlaceholder](uikit/uitextplaceholder.md)

### Managing the edit menu

- [editMenu(for:suggestedActions:)](uikit/uitextinput/editmenu(for:suggestedactions:).md)
- [willPresentEditMenu(animator:)](uikit/uitextinput/willpresenteditmenu(animator:).md)
- [willDismissEditMenu(animator:)](uikit/uitextinput/willdismisseditmenu(animator:).md)

### Supporting text-phrase alternatives

- [insertText(_:alternatives:style:)](uikit/uitextinput/inserttext(_:alternatives:style:).md)
- [UITextAlternativeStyle](uikit/uitextalternativestyle.md)

### Inserting a Smart Reply suggestion

- [insert(_:)](uikit/uitextinput/insert(_:).md)

### Supporting adaptive images

- [supportsAdaptiveImageGlyph](uikit/uitextinput/supportsadaptiveimageglyph.md)
- [insert(_:replacementRange:)](uikit/uitextinput/insert(_:replacementrange:).md)

### Returning text-styling information

- [textStyling(at:in:)](uikit/uitextinput/textstyling(at:in:).md)

### Reconciling text position and character offset

- [position(within:atCharacterOffset:)](uikit/uitextinput/position(within:atcharacteroffset:).md)
- [characterOffset(of:within:)](uikit/uitextinput/characteroffset(of:within:).md)

### Returning the text input view

- [textInputView](uikit/uitextinput/textinputview.md)

### Constants

- [UITextDirection](uikit/uitextdirection.md)
- [UITextStorageDirection](uikit/uitextstoragedirection.md)
- [UITextLayoutDirection](uikit/uitextlayoutdirection.md)

### Deprecated

- [UITextWritingDirection](uikit/uitextwritingdirection.md)
- [Style dictionary keys](uikit/style-dictionary-keys.md)

### Instance Properties

- [unobscuredContentRect](uikit/uitextinput/unobscuredcontentrect.md)

### Instance Methods

- [attributedText(in:)](uikit/uitextinput/attributedtext(in:).md)
- [didDismissWritingTools()](uikit/uitextinput/diddismisswritingtools().md)
- [insertAttributedText(_:)](uikit/uitextinput/insertattributedtext(_:).md)
- [replace(_:withAttributedText:)](uikit/uitextinput/replace(_:withattributedtext:).md)
- [willPresentWritingTools()](uikit/uitextinput/willpresentwritingtools().md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [UIKeyInput](uikit/uikeyinput.md)
- [UITextInputTraits](uikit/uitextinputtraits.md)

### Inherited By

- [UITextDraggable](uikit/uitextdraggable.md)
- [UITextDroppable](uikit/uitextdroppable.md)

### Conforming Types

- [UISearchTextField](uikit/uisearchtextfield.md)
- [UITextField](uikit/uitextfield.md)
- [UITextView](uikit/uitextview.md)

## See Also

### Text input

- [UITextInputDelegate](uikit/uitextinputdelegate.md)
- [UIKeyInput](uikit/uikeyinput.md)
- [UITextInputTraits](uikit/uitextinputtraits.md)
- [UITextInputContext](uikit/uitextinputcontext.md)
- [UITextInputMode](uikit/uitextinputmode.md)
- [UITextInputAssistantItem](uikit/uitextinputassistantitem.md)
- [UIDictationPhrase](uikit/uidictationphrase.md)
