O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

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

Assembling the Text System

For many applications that work with text, using NSTextView as the frontend interface to the text provides a great deal of functionality. This is by far the easiest way of working with the text system: you only need to drop a text view into your interface using Interface Builder, and you’re ready to go.

Using NSTextView’s APIs as the sole means of working with the text system does not offer the flexibility that can be achieved by assembling the individual components manually. By starting with an NSTextStorage object and adding layout managers, text containers, and text views, document layouts can have multiple columns and pages, have irregular areas of text, or present the same text in two different layouts.

Before exploring the manually assembly of text components, consider these rules that tell you what you can and cannot do:

  • A text storage object may have one or more layout manager objects that it manages.

  • Each layout manager instance may manage one or more instances of NSTextContainer.

  • Each text container has exactly one text view associated with it.

By varying the structure of the network with respect to the first two rules, you can create the possibilities mentioned earlier.

Several methods in NSTextStorage, NSLayoutManager, and NSTextContainer facilitate assembly and management of the object network.

NSTextStorage

This class offers the following methods for managing its layout managers:

addLayoutManager:

Adds the specified layout manager to the list of ...

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