O'Reilly logo

iOS 5 Programming Pushing the Limits: Developing Extraordinary Mobile Apps for Apple iPhone, iPad, and iPod Touch by Mugunth Kumar, Rob Napier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 UILabel, UITextField, and 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:

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required