Text Me

While table views are the go-to design containers for collecting brief snippets of content, the text itself is managed under the hood by one of the iPhone's text-savvy interface elements. When designing custom cells—or drawing text anywhere in an app, for that matter—developers use one of these four text containers. We'll explore these options over the next few pages, but here's the quick roundup:

To display longish, multiline text, iPhone developers use either text views or web views. Like table views, both of these elements have a built-in talent for scrolling. When the text to be displayed runs longer than the available space, swiping scrolls the text inside the boundaries of the text view's frame. Pour the chapter of a book into a text view, and you're all done, right? Bam, instant ebook! Well, not exactly. Text views aren't as useful as you might wish for long documents, because their text is completely uniform—the same for labels. You can set the color, font, and alignment of these text elements, but that change applies to all of the text inside. You can't italicize individual words, include a bold heading alongside regular text, or mix centered and left-aligned text—all you can have is just a single, uniform plain-text presentation.

For truly long-form text, where you typically need to offer more subtle formatting, you can instead turn to a web view. Web views are little web browsers embedded right into your interface but without the back button, location bar, or other controls we typically associate with a browser. Instead, a web view is just the viewport itself, an unadorned window to a web page—Safari without the toolbar. As you might expect, you can use web views to display website content inside your app (a topic you'll explore briefly in Roll Your Own: Browsers, Maps, and Email), but you can also use them to display formatted text. Instead of pointing your web view at the Internet, your app can feed it an internally generated "web page" with the formatted text. That means you can display headings, tables, and any type-addled mix of fonts you might dream up—anything a web page can show, a web view can show, too. In fact, some designers prefer to use web views not only to display formatted text, but to draw most or all of the app's interface using plain old HTML and CSS. (The techniques for coding apps this way are outside the scope of this book, but another book has you covered. Check out Building iPhone Apps with HTML, CSS, and JavaScript by Jonathan Stark for details about using this web-based technique.)

Text views (left) let you display and edit multiline text, as shown here in the Notes field of the Contacts app. Text fields (right) are suited to editing shorter snippets. Here, the Shopper app uses text fields to accept quantity and price info.
Text views (left) let you display and edit multiline text, as shown here in the Notes field of the Contacts app. Text fields (right) are suited to editing shorter snippets. Here, the Shopper app uses text fields to accept quantity and price info.

Figure 5-21. Text views (left) let you display and edit multiline text, as shown here in the Notes field of the Contacts app. Text fields (right) are suited to editing shorter snippets. Here, the Shopper app uses text fields to accept quantity and price info.