Chapter 18: Fancy Text Layout
There are several options for displaying text in iOS. There are simple controls like
UILabel and full rendering engines like
UIWebView. For complete control, including laying out columns or drawing text along a path, you can implement your own layout engine with Core Text. Unfortunately, there is no easy-to-use rich text control available. Each option has significant restrictions. In this chapter you explore the choices available and learn how to make the most of them within their limitations, while we all wait for the day that Apple finally provides
UIRichTextView. You also take a brief look at some of the third-party options available.
The Normal Stuff: Fields, Views, and Labels
You’re probably already familiar with
UITextView, so I discuss them only briefly here. They are the basic controls you use for day-to-day text layout.
UILabel is a lightweight, static text control. It is very common for developers to have problems with dynamic labels (labels with contents set programmatically) they create in Interface Builder. Here are a few tips for using
UILabel can display multiline text. Just set its
numberOfLines property in code or the Lines property in Interface Builder. This is the maximum number of lines. If you want it to be unbounded, set it to zero.
■ By default, Interface Builder turns on
adjustsFontSizeToFitWidth. This can be surprising if you assign text that is wider than the label. Rather than truncating ...