O'Reilly logo

iOS 6 Programming Pushing the Limits: Advanced Application Development 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 26: 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.

iOS 6 brings rich text to all of UIKit. Finally, you can display and edit bold and underline without using a web view or Core Text, which greatly simplifies many programs. To get the most out of iOS rich text, you need to understand NSAttributedString as explained in this chapter. After you understand attributed strings, handling rich text is mostly just a matter of requesting it from your text views.

After you’ve mastered attributed strings, you can take full control of text layout using Core Text. In this chapter, you learn about the major parts of Core Text, how to use them to lay out text any way you like, and the limitations that you still need to work around.

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’re the basic controls you use for day-to-day text layout.

UILabel is a lightweight, static text control. It’s 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 ...

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