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

Name

NSAttributedString — Mac OS X 10.0

Synopsis

This class represents a string with associated attributes that describe the styled appearance of the string. Attributes are stored in a dictionary. Cocoa defines several keys to identify common attributes such as the font, foreground color, text alignment, line spacing, and more; these keys are listed below in the constants. This class has many methods for querying the attributes of ranges of text within the string. For example, the method attributesAtIndex:effectiveRange: returns a dictionary of attributes for the character at index, and by reference the range that the attribute applies to is returned in the second parameter.

The Application Kit implements many extensions to NSAttributedString to support more graphical uses of this class. In particular, the AppKit extensions provide support for initializing an attributed string with RTF-formatted data, as well as converting an attributed string to such data. Additionally, these extensions provide for drawing attributed strings into a view, and for managing graphics attributes such as font and ruler characteristics.

NSAttributedString is an immutable class. Mutability is supported in the subclass NSMutable-AttributedString.

image with no caption

@interface NSAttributedString : NSObject <NSCoding, NSCopying, NSMutableCopying>
                                  // Initializers
   - (id)initWithAttributedString:(NSAttributedString *)attrStr ...

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