Chapter 23. Text
Text can be displayed in various ways:
- Displays text, possibly consisting of multiple lines, in a single font and size, with color (and highlighted color), alignment, and wrapping and truncation. Discussed in this chapter.
- Displays a single line of editable text, in a single font and size, with color and alignment; may have a border, may have a background image, and overlay views may appear at its right and left end. Discussed in this chapter; a UITextField is a UIControl subclass, so see also Chapter 25.
- Displays scrollable text, possibly editable, in a single font and size, with color and alignment; can use data detectors to display tappable links. Discussed in this chapter.
- A scrollable view displaying rendered HTML. Because HTML can express text attribute spans, this is a good way to show text in multiple fonts, sizes, colors, alignments, and so on, and to include images and tappable links. Can also display various additional document types, such as PDF, RTF, and .doc. Discussed in the next chapter.
There are three main ways to draw strings directly:
- Core Graphics
- Low-level methods for drawing text (not NSStrings). For drawing in general, see Chapter 15.
At a high level, the UIStringDrawing category on NSString endows strings with the ability to draw themselves, along with metrics methods (the
sizeWithFont...methods) for learning the dimensions at which a given string will be drawn. NSString ...