<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITextView"
  },
  "title" : "UITextView"
}
-->

# UITextView

A scrollable, multiline text region.

```
@MainActor class UITextView
```

## Overview

A text view displays multiple lines of text and supports editing, custom styles, and rich formatting. Use it when you need to display or edit a body of text, such as the contents of a document.

For rich text, set the [`attributedText`](/documentation/UIKit/UITextView/attributedText) property to provide per-range style information. You can also use [`font`](/documentation/UIKit/UITextView/font), [`textColor`](/documentation/UIKit/UITextView/textColor), and [`textAlignment`](/documentation/UIKit/UITextView/textAlignment) to apply a single style across all text in the view.

### Manage the keyboard

When someone taps in an editable text view, it becomes the first responder and the system displays the keyboard. Because the keyboard can obscure parts of your interface, reposition any views that would otherwise be hidden. Some system views, like table views, scroll the first responder into view automatically. If the first responder is at the bottom of the scrolling region, you may still need to resize or reposition the scroll view to keep it visible.

Your app is responsible for dismissing the keyboard. Dismiss it in response to a user action, such as tapping a Done button. To dismiss the keyboard, call [`resignFirstResponder()`](/documentation/UIKit/UIResponder/resignFirstResponder()) on the text view that’s currently the first responder. This ends the editing session and hides the keyboard, with your delegate’s consent.

To customize the keyboard, use the properties from the [`UITextInputTraits`](/documentation/UIKit/UITextInputTraits) protocol, which text views implement. You can set the keyboard type (ASCII, Numbers, URL, Email, and others) and configure text entry behavior like autocapitalization and autocorrection.

### Keyboard notifications

When the system shows or hides the keyboard, it posts notifications that include the keyboard’s size and position. Register for these notifications to reposition or resize views as needed:

- [`keyboardWillShowNotification`](/documentation/UIKit/UIResponder/keyboardWillShowNotification)
- [`keyboardDidShowNotification`](/documentation/UIKit/UIResponder/keyboardDidShowNotification)
- [`keyboardWillHideNotification`](/documentation/UIKit/UIResponder/keyboardWillHideNotification)
- [`keyboardDidHideNotification`](/documentation/UIKit/UIResponder/keyboardDidHideNotification)

For more information about these notifications, see [`UIWindow`](/documentation/UIKit/UIWindow).

### State preservation

If you assign a value to this view’s [`restorationIdentifier`](/documentation/UIKit/UIView/restorationIdentifier) property, the view preserves the following information:

- The selected range of text.
- The editing state of the text view, as reported by the [`isEditable`](/documentation/UIKit/UITextView/isEditable) property.

On the next launch, the view restores these properties. If the saved selection range doesn’t apply to the current text, no text is selected.

For design guidance, see [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/components/content/text-views/).

## Topics

### Initializing the text view

[`init(frame:textContainer:)`](/documentation/UIKit/UITextView/init(frame:textContainer:))

Creates a new text view with the specified text container.

[`init(usingTextLayoutManager:)`](/documentation/UIKit/UITextView/init(usingTextLayoutManager:))

Creates a new text view, with or without a text layout manager depending on the Boolean value you specify.

[`init(coder:)`](/documentation/UIKit/UITextView/init(coder:))

Creates a text view from data in an unarchiver.

### Specifying the text content

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

The text that the text view displays.

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

The styled text that the text view displays.

### Responding to text view changes

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

The text view’s delegate.

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

The methods for receiving editing-related messages for text view objects.

### Configuring appearance attributes

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

The font of the text.

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

The color of the text.

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

The technique for aligning the text.

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

The attributes to apply to new text that the user enters.

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

The attributes to apply to links.

[`borderStyle`](/documentation/UIKit/UITextView/borderStyle-swift.property)

The border style for the text field.

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

[`drawTextHighlightBackground(for:origin:)`](/documentation/UIKit/UITextView/drawTextHighlightBackground(for:origin:))

[`UITextView.BorderStyle`](/documentation/UIKit/UITextView/BorderStyle-swift.enum)

The type of border around the text view.

### Configuring layout attributes

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

The inset of the text container’s layout area within the text view’s content area.

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

A Boolean value that determines the rendering scale of the text.

[`sizingRule`](/documentation/UIKit/UILetterformAwareAdjusting/sizingRule)

The typographic bounds-sizing behavior that handles text with fonts that contain oversize characters.

### Formatting special data in text

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

The types of data that convert to tappable URLs in the text view.

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

Constants that define the types of information to detect in text-based content.

### Managing the editing behavior

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

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

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

A Boolean value that indicates whether the text view allows the user to edit style information.

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

A notification that alerts observers when an editing session begins in a text view.

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

A notification that alerts observers when the text in a text view changes.

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

A notification that alerts observers when the editing session ends for a text view.

### Working with the selection

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

The current selection range of the text view.

[`scrollRangeToVisible(_:)`](/documentation/UIKit/UITextView/scrollRangeToVisible(_:))

Scrolls the text view until the text in the specified range is visible.

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

A Boolean value that indicates whether inserting text replaces the previous contents.

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

A Boolean value that indicates whether the text view is selectable.

### Replacing the system input views

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

The custom input view to display when the text view becomes the first responder.

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

The custom accessory view to display when the text view becomes the first responder.

### Supporting Find and Replace

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

A Boolean value that enables a text view’s built-in find interaction.

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

The text view’s built-in find interaction.

### Getting the Writing Tools configuration

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

The level of Writing Tools support to use in the text view.

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

The type of content Writing Tools generates for your text view.

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

A Boolean value that indicates whether the writing tools are currently interacting with the text view’s content.

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

The object that coordinates interactions between Writing Tools and the text view.

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

### Accessing TextKit Objects

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

The text layout manager that lays out text for the text view’s text container.

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

The layout manager that lays out text for the text view’s text container.

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

The text container object that defines the area where text displays in the text view.

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

The text storage object holding the text that displays in the text view.

### Customizing viewport layout

[`viewportBounds(for:)`](/documentation/UIKit/UITextView/viewportBounds(for:))

`NSTextViewportLayoutControllerDelegate` method that the framework calls to request the current viewport, which is the view visible bounds plus the overdraw area. Requires a call to super.

[`textViewportLayoutControllerWillLayout(_:)`](/documentation/UIKit/UITextView/textViewportLayoutControllerWillLayout(_:))

`NSTextViewportLayoutControllerDelegate` method that the framework calls when the text viewport layout controller starts its layout process. Requires a call to super.

[`textViewportLayoutControllerDidLayout(_:)`](/documentation/UIKit/UITextView/textViewportLayoutControllerDidLayout(_:))

`NSTextViewportLayoutControllerDelegate` method that the framework calls when the text viewport layout controller finishes its layout process. Requires a call to super.

[`textViewportLayoutControllerReceivedSetNeedsLayout(_:)`](/documentation/UIKit/UITextView/textViewportLayoutControllerReceivedSetNeedsLayout(_:))

`NSTextViewportLayoutControllerDelegate` method that the framework calls when the text viewport layout controller receives a `setNeedsLayout` call. Requires a call to super.

### Managing attachment view reuse

[`register(_:forTextAttachmentViewProviderType:)`](/documentation/UIKit/UITextView/register(_:forTextAttachmentViewProviderType:))

Register the UITextAttachmentViewProviderReusePolicy for all instances of a particular subclass of NSTextAttachmentViewProvider.

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

An option set that controls whether a text view reuses attachment view providers when scrolling or editing.

### Supporting state restoration

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



---

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)