A scrollable, multiline text region.


@interface UITextView : UIScrollView


UITextView supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.

This class supports multiple text styles through use of the attributedText property. (Styled text is not supported in versions of iOS earlier than iOS 6.) Setting a value for this property causes the text view to use the style information provided in the attributed string. You can still use the font, textColor, and textAlignment properties to set style attributes, but those properties apply to all of the text in the text view. It’s recommended that you use a text view—and not a UIWebView object—to display both plain and rich text in your app.

Managing the Keyboard

When the user taps in an editable text view, that text view becomes the first responder and automatically asks the system to display the associated keyboard. Because the appearance of the keyboard has the potential to obscure portions of your user interface, it is up to you to make sure that does not happen by repositioning any views that might be obscured. Some system views, like table views, help you by scrolling the first responder into view automatically. If the first responder is at the bottom of the scrolling region, however, you may still need to resize or reposition the scroll view itself to ensure the first responder is visible.

It is your application’s responsibility to dismiss the keyboard at the time of your choosing. You might dismiss the keyboard in response to a specific user action, such as the user tapping a particular button in your user interface. To dismiss the keyboard, send the resignFirstResponder message to the text view that is currently the first responder. Doing so causes the text view object to end the current editing session (with the delegate object’s consent) and hide the keyboard.

The appearance of the keyboard itself can be customized using the properties provided by the UITextInputTraits protocol. Text view objects implement this protocol and support the properties it defines. You can use these properties to specify the type of keyboard (ASCII, Numbers, URL, Email, and others) to display. You can also configure the basic text entry behavior of the keyboard, such as whether it supports automatic capitalization and correction of the text.

Keyboard Notifications

When the system shows or hides the keyboard, it posts several keyboard notifications. These notifications contain information about the keyboard, including its size, which you can use for calculations that involve repositioning or resizing views. Registering for these notifications is the only way to get some types of information about the keyboard. The system delivers the following notifications for keyboard-related events:

For more information about these notifications, see their descriptions in UIWindow.

State Preservation

In iOS 6 and later, if you assign a value to this view’s restorationIdentifier property, it preserves the following information:

  • The selected range of text, as reported by the selectedRange property.

  • The editing state of the text view, as reported by the editable property.

During the next launch cycle, the view attempts to restore these properties to their saved values. If the selection range cannot be applied to the text in the restored view, no text is selected. For more information about how state preservation and restoration works, see App Programming Guide for iOS.

For more information about appearance and behavior configuration, see Text Views.


Initializing the Text View

- initWithFrame:textContainer:

Creates a new text view with the specified text container.

Responding to Text View Changes


The receiver’s delegate.


The UITextViewDelegate protocol defines a set of optional methods you can use to receive editing-related messages for UITextView objects. All of the methods in this protocol are optional. You can use them in situations where you might want to adjust the text being edited (such as in the case of a spell checker program) or modify the intended insertion point.

Configuring the Text Attributes


The text displayed by the text view.


The styled text displayed by the text view.


The font of the text.


The color of the text.


A Boolean value indicating whether the receiver is editable.


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


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


The technique to use for aligning the text.

- hasText

Returns a Boolean value indicating whether the text view currently contains any text.


The attributes to apply to new text being entered by the user.


The attributes to apply to links.


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

Working with the Selection


The current selection range of the receiver.

- scrollRangeToVisible:

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


A Boolean value indicating whether inserting text replaces the previous contents.


A Boolean value indicating whether the receiver is selectable.

Replacing the System Input Views


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


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

Accessing Text Kit Objects


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


The text container object defining the area in which text is displayed in this text view.


The text storage object holding the text displayed in this text view.



Notifies observers that an editing session began in a text view. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.


Notifies observers that the text in a text view changed. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.


Notifies observers that the editing session ended for a text view. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.



Defines the types of information that can be detected in text-based content.

Instance Properties


Inherits From

See Also

Text Views


A view that displays one or more lines of informational text.


An object that displays an editable text area in your interface.

Drag and Drop Customization

Extend the standard drag and drop support for text views to include custom types of content.