| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Companion guide | |
| Declared in | UITextView.h |
| Related sample code |
The UITextView class implements the behavior for a scrollable, multiline text region. The class supports the display of text using a custom font, color, and alignment 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 does not support multiple styles for text. The font, color, and text alignment attributes you specify always apply to the entire contents of the text view. To display more complex styling in your application, you need to use a UIWebView object and render your content using HTML.
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.
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 Class Reference.
text property
font property
textColor property
editable property
dataDetectorTypes property
textAlignment property
– hasText
selectedRange property
– scrollRangeToVisible:
delegate property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The types of data converted to clickable URLs in the text view.
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes
You can use this property to specify the types of data (phone numbers, http links, and so on) that should be automatically converted to clickable URLs in the text view. When clicked, the text view opens the application responsible for handling the URL type and passes it the URL.
UITextView.hThe receiver’s delegate.
@property(nonatomic, assign) id<UITextViewDelegate> delegate
A text view delegate responds to editing-related messages from the text view. You can use the delegate to track changes to the text itself and to the current selection.
For information about the methods implemented by the delegate, see UITextViewDelegate Protocol Reference.
UITextView.hA Boolean value indicating whether the receiver is editable.
@property(nonatomic, getter=isEditable) BOOL editable
The default value of this property is YES.
UITextView.hThe font of the text.
@property(nonatomic, retain) UIFont *font
This property applies to the entire text string. The default font is a 17-point Helvetica plain font.
UIFont class. UITextView.hThe current selection range of the receiver.
@property(nonatomic) NSRange selectedRange
In iPhone OS 2.2 and earlier, the length of the selection range is always 0, indicating that the selection is actually an insertion point. In iPhone OS 3.0 and later, the length of the selection range may be non-zero.
UITextView.hThe text displayed by the text view.
@property(nonatomic, copy) NSString *text
UITextView.hThe technique to use for aligning the text.
@property(nonatomic) UITextAlignment textAlignment
This property applies to the entire text string. The default value of this property is UITextAlignmentLeft.
UITextView.hThe color of the text.
@property(nonatomic, retain) UIColor *textColor
This property applies to the entire text string. The default text color is black.
@property backgroundColor (UIView)UITextView.hReturns a Boolean value indicating whether the text view currently contains any text.
- (BOOL)hasText
YES if the receiver contains text or NO if it does not.
UITextView.hScrolls the receiver until the text in the specified range is visible.
- (void)scrollRangeToVisible:(NSRange)range
The range of text to scroll into view.
UITextView.hNotifies 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.
UITextView.hNotifies 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.
UITextView.hNotifies 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.
UITextView.hLast updated: 2009-07-23