---
title: UITextView
framework: uikit
role: symbol
role_heading: Class
path: uikit/uitextview
---

# UITextView

A scrollable, multiline text region.

## Declaration

```swift
@MainActor class UITextView
```

## Mentioned in

Customizing Writing Tools behavior for UIKit views Managing viewport layout and attachment reuse in text views About app development with UIKit Adding tables to attributed strings in UIKit Adding Writing Tools support to a custom UIKit view Adopting system selection UI in custom text views Building a desktop-class iPad app Making a view into a drag source Making a view into a drop destination

## Overview

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 property to provide per-range style information. You can also use font, textColor, and 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() 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 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 keyboardDidShowNotification keyboardWillHideNotification keyboardDidHideNotification For more information about these notifications, see UIWindow. State preservation If you assign a value to this view’s 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 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.

## Topics

### Initializing the text view

- [init(frame:textContainer:)](uikit/uitextview/init(frame:textcontainer:).md)
- [init(usingTextLayoutManager:)](uikit/uitextview/init(usingtextlayoutmanager:).md)
- [init(coder:)](uikit/uitextview/init(coder:).md)

### Specifying the text content

- [text](uikit/uitextview/text.md)
- [attributedText](uikit/uitextview/attributedtext.md)

### Responding to text view changes

- [delegate](uikit/uitextview/delegate.md)
- [UITextViewDelegate](uikit/uitextviewdelegate.md)

### Configuring appearance attributes

- [font](uikit/uitextview/font.md)
- [textColor](uikit/uitextview/textcolor.md)
- [textAlignment](uikit/uitextview/textalignment.md)
- [typingAttributes](uikit/uitextview/typingattributes.md)
- [linkTextAttributes](uikit/uitextview/linktextattributes.md)
- [borderStyle](uikit/uitextview/borderstyle-swift.property.md)
- [textHighlightAttributes](uikit/uitextview/texthighlightattributes.md)
- [drawTextHighlightBackground(for:origin:)](uikit/uitextview/drawtexthighlightbackground(for:origin:).md)
- [UITextView.BorderStyle](uikit/uitextview/borderstyle-swift.enum.md)

### Configuring layout attributes

- [textContainerInset](uikit/uitextview/textcontainerinset.md)
- [usesStandardTextScaling](uikit/uitextview/usesstandardtextscaling.md)
- [sizingRule](uikit/uiletterformawareadjusting/sizingrule.md)

### Formatting special data in text

- [dataDetectorTypes](uikit/uitextview/datadetectortypes.md)
- [UIDataDetectorTypes](uikit/uidatadetectortypes.md)

### Managing the editing behavior

- [isEditable](uikit/uitextview/iseditable.md)
- [allowsEditingTextAttributes](uikit/uitextview/allowseditingtextattributes.md)
- [textDidBeginEditingNotification](uikit/uitextview/textdidbegineditingnotification.md)
- [textDidChangeNotification](uikit/uitextview/textdidchangenotification.md)
- [textDidEndEditingNotification](uikit/uitextview/textdidendeditingnotification.md)

### Working with the selection

- [selectedRange](uikit/uitextview/selectedrange.md)
- [scrollRangeToVisible(_:)](uikit/uitextview/scrollrangetovisible(_:).md)
- [clearsOnInsertion](uikit/uitextview/clearsoninsertion.md)
- [isSelectable](uikit/uitextview/isselectable.md)

### Replacing the system input views

- [inputView](uikit/uitextview/inputview.md)
- [inputAccessoryView](uikit/uitextview/inputaccessoryview.md)

### Supporting Find and Replace

- [isFindInteractionEnabled](uikit/uitextview/isfindinteractionenabled.md)
- [findInteraction](uikit/uitextview/findinteraction.md)

### Getting the Writing Tools configuration

- [writingToolsBehavior](uikit/uitextview/writingtoolsbehavior.md)
- [allowedWritingToolsResultOptions](uikit/uitextview/allowedwritingtoolsresultoptions.md)
- [isWritingToolsActive](uikit/uitextview/iswritingtoolsactive.md)
- [writingToolsCoordinator](uikit/uitextview/writingtoolscoordinator.md)
- [subclassForWritingToolsCoordinator](uikit/uitextview/subclassforwritingtoolscoordinator.md)

### Accessing TextKit Objects

- [textLayoutManager](uikit/uitextview/textlayoutmanager.md)
- [layoutManager](uikit/uitextview/layoutmanager.md)
- [textContainer](uikit/uitextview/textcontainer.md)
- [textStorage](uikit/uitextview/textstorage.md)

### Customizing viewport layout

- [viewportBounds(for:)](uikit/uitextview/viewportbounds(for:).md)
- [textViewportLayoutControllerWillLayout(_:)](uikit/uitextview/textviewportlayoutcontrollerwilllayout(_:).md)
- [textViewportLayoutControllerDidLayout(_:)](uikit/uitextview/textviewportlayoutcontrollerdidlayout(_:).md)
- [textViewportLayoutControllerReceivedSetNeedsLayout(_:)](uikit/uitextview/textviewportlayoutcontrollerreceivedsetneedslayout(_:).md)

### Managing attachment view reuse

- [register(_:forTextAttachmentViewProviderType:)](uikit/uitextview/register(_:fortextattachmentviewprovidertype:).md)
- [UITextAttachmentViewProviderReusePolicy](uikit/uitextattachmentviewproviderreusepolicy.md)

### Supporting state restoration

- [interactionState](uikit/uitextview/interactionstate.md)

### Structures

- [UITextView.TextDidBeginEditingMessage](uikit/uitextview/textdidbegineditingmessage.md)
- [UITextView.TextDidChangeMessage](uikit/uitextview/textdidchangemessage.md)
- [UITextView.TextDidEndEditingMessage](uikit/uitextview/textdidendeditingmessage.md)

### Instance Properties

- [selectedRanges](uikit/uitextview/selectedranges-70g3h.md)
- [textFormattingConfiguration](uikit/uitextview/textformattingconfiguration.md)

### Instance Methods

- [textViewportLayoutController(_:configureRenderingSurfaceFor:)](uikit/uitextview/textviewportlayoutcontroller(_:configurerenderingsurfacefor:).md)

## Relationships

### Inherits From

- [UIScrollView](uikit/uiscrollview.md)

### Conforms To

- [CALayerDelegate](quartzcore/calayerdelegate.md)
- [CLBodyIdentifiable](corelocation/clbodyidentifiable.md)
- [CMBodyIdentifiable](coremotion/cmbodyidentifiable.md)
- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSTextViewportLayoutControllerDelegate](uikit/nstextviewportlayoutcontrollerdelegate.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [UIAccessibilityIdentification](uikit/uiaccessibilityidentification.md)
- [UIActivityItemsConfigurationProviding](uikit/uiactivityitemsconfigurationproviding.md)
- [UIAppearance](uikit/uiappearance.md)
- [UIAppearanceContainer](uikit/uiappearancecontainer.md)
- [UIContentSizeCategoryAdjusting](uikit/uicontentsizecategoryadjusting.md)
- [UICoordinateSpace](uikit/uicoordinatespace.md)
- [UIDynamicItem](uikit/uidynamicitem.md)
- [UIFindInteractionDelegate](uikit/uifindinteractiondelegate.md)
- [UIFocusEnvironment](uikit/uifocusenvironment.md)
- [UIFocusItem](uikit/uifocusitem.md)
- [UIFocusItemContainer](uikit/uifocusitemcontainer.md)
- [UIFocusItemScrollableContainer](uikit/uifocusitemscrollablecontainer.md)
- [UIKeyInput](uikit/uikeyinput.md)
- [UILargeContentViewerItem](uikit/uilargecontentvieweritem.md)
- [UILetterformAwareAdjusting](uikit/uiletterformawareadjusting.md)
- [UIPasteConfigurationSupporting](uikit/uipasteconfigurationsupporting.md)
- [UIPopoverPresentationControllerSourceItem](uikit/uipopoverpresentationcontrollersourceitem.md)
- [UIResponderStandardEditActions](uikit/uiresponderstandardeditactions.md)
- [UITextDraggable](uikit/uitextdraggable.md)
- [UITextDroppable](uikit/uitextdroppable.md)
- [UITextInput](uikit/uitextinput.md)
- [UITextInputTraits](uikit/uitextinputtraits.md)
- [UITextPasteConfigurationSupporting](uikit/uitextpasteconfigurationsupporting.md)
- [UITextSearching](uikit/uitextsearching-3wkjv.md)
- [UITraitChangeObservable](uikit/uitraitchangeobservable-67e94.md)
- [UITraitEnvironment](uikit/uitraitenvironment.md)
- [UIUserActivityRestoring](uikit/uiuseractivityrestoring.md)

## See Also

### Text views

- [UILabel](uikit/uilabel.md)
- [UITextField](uikit/uitextfield.md)
- [Drag and drop customization](uikit/drag-and-drop-customization.md)
