UITextView

A text view (UITextView) is sort of a scrollable, multiline version of a text field (UITextField, with which it should not be confused). It is a scroll view subclass (UIScrollView, Chapter 20), and thus has (by default) no border; it is not a control. It has text, font, textColor, and textAlignment properties; it can be editable or not, according to its editable property. (You might use a scrollable noneditable text view instead of a UILabel, so as not to be limited to a fixed number of lines of text.) An editable text view governs its keyboard just as a text field does: when it is first responder, it is being edited and shows the keyboard, and it implements the UITextInput protocol and has inputView and inputAccessoryView properties. Its menu works the same way as a text field’s.

One big difference, from the programmer’s point of view, between a text view and a text field is that a text view gives you information about, and control of, its selection: it has a selectedRange property which you can get and set, and it adds a scrollRangeToVisible: method so that you can scroll in terms of a range of its text. The selectedRange is useful especially if the text view is first responder, because the selection is then meaningful and visible, but it does work (invisibly) even if the text view is not first responder. (You could take advantage of the selectedRange, for example, to customize a text view’s menu with more intelligence than in our text field example in the previous ...

Get Programming iOS 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.