Text Views
The UITextView class is based on a UIView, however, its functionality has been extended to present and allow editing of text, provide scrolling, and handle various fonts and colors. Text views can be easily abused, and are only recommended for text-based portions of an application, such as an electronic book, notes section of a program, or informational page to present unstructured information.
A UITextView object inherits from UIScroller, which is a generic scrollable class. This means that the text view itself comes pre-equipped with all scrolling functionality, so the developer can focus on presenting content rather than programming scroll bars. The UIScroller class inherits from UIView, which, as discussed in the last section, is the base class for all view classes.
Creating a Text View
Because UITextView is ultimately derived from UIView, it is created in the same fashion as the main view objects created in the last section—using an initWithFrame method.
UITextView *textView = [ [ UITextView alloc ]
initWithFrame: viewRect ];
Once the view is created, a number of different properties can then be set.
Editing
If the text view is being used to collect user input, it will need to be made editable:
[ textView setEditable: YES ];
If the view is simply presenting data that should not be edited, this feature should be disabled.
Margins
The size of the top margin is the only margin that can be set in the text view. The value represents the number of pixels from the top of the text ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access