<!--
{
  "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: CGRect, textContainer: NSTextContainer?)`](/documentation/UIKit/UITextView/init(frame:textContainer:))

Creates a new text view with the specified text container.

[`convenience init(usingTextLayoutManager: Bool)`](/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: NSCoder)`](/documentation/UIKit/UITextView/init(coder:))

Creates a text view from data in an unarchiver.

### Specifying the text content

[`var text: String!`](/documentation/UIKit/UITextView/text)

The text that the text view displays.

[`var attributedText: NSAttributedString!`](/documentation/UIKit/UITextView/attributedText)

The styled text that the text view displays.

### Responding to text view changes

[`var delegate: (any UITextViewDelegate)?`](/documentation/UIKit/UITextView/delegate)

The text view’s delegate.

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

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

### Configuring appearance attributes

[`var font: UIFont?`](/documentation/UIKit/UITextView/font)

The font of the text.

[`var textColor: UIColor?`](/documentation/UIKit/UITextView/textColor)

The color of the text.

[`var textAlignment: NSTextAlignment`](/documentation/UIKit/UITextView/textAlignment)

The technique for aligning the text.

[`var typingAttributes: [NSAttributedString.Key : Any]`](/documentation/UIKit/UITextView/typingAttributes)

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

[`var linkTextAttributes: [NSAttributedString.Key : Any]!`](/documentation/UIKit/UITextView/linkTextAttributes)

The attributes to apply to links.

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

The border style for the text field.

[`var textHighlightAttributes: [NSAttributedString.Key : Any]!`](/documentation/UIKit/UITextView/textHighlightAttributes)

[`func drawTextHighlightBackground(for: NSTextRange, origin: CGPoint)`](/documentation/UIKit/UITextView/drawTextHighlightBackground(for:origin:))

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

The type of border around the text view.

### Configuring layout attributes

[`var textContainerInset: UIEdgeInsets`](/documentation/UIKit/UITextView/textContainerInset)

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

[`var usesStandardTextScaling: Bool`](/documentation/UIKit/UITextView/usesStandardTextScaling)

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

[`var sizingRule: UILetterformAwareSizingRule`](/documentation/UIKit/UILetterformAwareAdjusting/sizingRule)

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

### Formatting special data in text

[`var dataDetectorTypes: UIDataDetectorTypes`](/documentation/UIKit/UITextView/dataDetectorTypes)

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

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

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

### Managing the editing behavior

[`var isEditable: Bool`](/documentation/UIKit/UITextView/isEditable)

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

[`var allowsEditingTextAttributes: Bool`](/documentation/UIKit/UITextView/allowsEditingTextAttributes)

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

[`class let textDidBeginEditingNotification: NSNotification.Name`](/documentation/UIKit/UITextView/textDidBeginEditingNotification)

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

[`class let textDidChangeNotification: NSNotification.Name`](/documentation/UIKit/UITextView/textDidChangeNotification)

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

[`class let textDidEndEditingNotification: NSNotification.Name`](/documentation/UIKit/UITextView/textDidEndEditingNotification)

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

### Working with the selection

[`var selectedRange: NSRange`](/documentation/UIKit/UITextView/selectedRange)

The current selection range of the text view.

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

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

[`var clearsOnInsertion: Bool`](/documentation/UIKit/UITextView/clearsOnInsertion)

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

[`var isSelectable: Bool`](/documentation/UIKit/UITextView/isSelectable)

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

### Replacing the system input views

[`var inputView: UIView?`](/documentation/UIKit/UITextView/inputView)

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

[`var inputAccessoryView: UIView?`](/documentation/UIKit/UITextView/inputAccessoryView)

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

### Supporting Find and Replace

[`var isFindInteractionEnabled: Bool`](/documentation/UIKit/UITextView/isFindInteractionEnabled)

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

[`var findInteraction: UIFindInteraction?`](/documentation/UIKit/UITextView/findInteraction)

The text view’s built-in find interaction.

### Getting the Writing Tools configuration

[`var writingToolsBehavior: UIWritingToolsBehavior`](/documentation/UIKit/UITextView/writingToolsBehavior)

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

[`var allowedWritingToolsResultOptions: UIWritingToolsResultOptions`](/documentation/UIKit/UITextView/allowedWritingToolsResultOptions)

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

[`var isWritingToolsActive: Bool`](/documentation/UIKit/UITextView/isWritingToolsActive)

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

[`var writingToolsCoordinator: UIWritingToolsCoordinator`](/documentation/UIKit/UITextView/writingToolsCoordinator)

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

[`var subclassForWritingToolsCoordinator: AnyClass`](/documentation/UIKit/UITextView/subclassForWritingToolsCoordinator)

### Accessing TextKit Objects

[`var textLayoutManager: NSTextLayoutManager?`](/documentation/UIKit/UITextView/textLayoutManager)

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

[`var layoutManager: NSLayoutManager`](/documentation/UIKit/UITextView/layoutManager)

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

[`var textContainer: NSTextContainer`](/documentation/UIKit/UITextView/textContainer)

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

[`var textStorage: NSTextStorage`](/documentation/UIKit/UITextView/textStorage)

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

### Customizing viewport layout

[`func viewportBounds(for: NSTextViewportLayoutController) -> CGRect`](/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.

[`func textViewportLayoutControllerWillLayout(NSTextViewportLayoutController)`](/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.

[`func textViewportLayoutControllerDidLayout(NSTextViewportLayoutController)`](/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.

[`func textViewportLayoutControllerReceivedSetNeedsLayout(NSTextViewportLayoutController)`](/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

[`func register(UITextAttachmentViewProviderReusePolicy, forTextAttachmentViewProviderType: AnyClass)`](/documentation/UIKit/UITextView/register(_:forTextAttachmentViewProviderType:))

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

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

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

### Supporting state restoration

[`var interactionState: Any`](/documentation/UIKit/UITextView/interactionState)

### Structures

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

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

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

### Instance Properties

[`var selectedRanges: [NSRange]`](/documentation/UIKit/UITextView/selectedRanges-70g3h)

[`var textFormattingConfiguration: UITextFormattingViewController.Configuration?`](/documentation/UIKit/UITextView/textFormattingConfiguration)

For text views that have flag `allowsEditingTextAttributes` set,
this configuration will be used for `UITextFormattingViewController`
when its presentation is requested.

### Instance Methods

[`func textViewportLayoutController(NSTextViewportLayoutController, configureRenderingSurfaceFor: NSTextLayoutFragment)`](/documentation/UIKit/UITextView/textViewportLayoutController(_:configureRenderingSurfaceFor:))

`NSTextViewportLayoutControllerDelegate` method that the framework calls when the layout controller lays out a text layout fragment in the UI. Requires a call to super.

## Relationships

### Inherits From

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

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

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

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

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

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

[`CVarArg`](/documentation/Swift/CVarArg)

[`CALayerDelegate`](/documentation/QuartzCore/CALayerDelegate)

[`Equatable`](/documentation/Swift/Equatable)

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

[`Escapable`](/documentation/Swift/Escapable)

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

[`Copyable`](/documentation/Swift/Copyable)

[`CMBodyIdentifiable`](/documentation/CoreMotion/CMBodyIdentifiable)

[`Hashable`](/documentation/Swift/Hashable)

[`Sendable`](/documentation/Swift/Sendable)

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

[`NSCoding`](/documentation/Foundation/NSCoding)

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

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

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

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

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

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

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

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

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

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

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

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

[`UITextSearching-3wkjv`](/documentation/UIKit/UITextSearching-3wkjv)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

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

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

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

[`CLBodyIdentifiable`](/documentation/CoreLocation/CLBodyIdentifiable)

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

[`UITraitChangeObservable-67e94`](/documentation/UIKit/UITraitChangeObservable-67e94)

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

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

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

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

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

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

---

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)