NSAttributedString — Mac OS X 10.0


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

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.