NSAttributedString UIKit Additions Reference

Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 6.0 and later.
Declared in
NSAttributedString.h
NSStringDrawing.h
NSTextAttachment.h

Overview

The UIKit framework adds methods to NSAttributedString to support the drawing of styled strings and to compute the size and metrics of a string prior to drawing. None of these methods affects the contents of the object itself, only how it is drawn on screen.

By default, strings are drawn using the native coordinate system of iOS, where content is drawn down and to the right from the specified origin point. Whenever you are positioning string content, you should keep this orientation in mind and use the upper-left corner of the string’s bounding box as the origin point for drawing.

You may use the methods described in this class extension from secondary threads in your app and not just from the main thread. However, if you use any of the methods that support an NSStringDrawingContext object, you must not share contexts across threads or dispatch queues.

Tasks

Creating an Attributed String

Drawing the String

Getting Metrics for the String

Generating Data

Class Methods

attributedStringWithAttachment:

Creates an attributed string with an attachment.

+ (NSAttributedString *)attributedStringWithAttachment:(NSTextAttachment *)attachment
Parameters
attachment

The attachment.

Return Value

An attributed string containing the attachment.

Discussion

This is a convenience method for creating an attributed string containing an attachment using NSAttachmentCharacter as the base character.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSTextAttachment.h

Instance Methods

boundingRectWithSize:options:context:

Returns the bounding rectangle required to draw the string.

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
Parameters
size

The width and height constraints to apply when computing the string’s bounding rectangle.

options

Additional drawing options to apply to the string during rendering. For a list of possible values, see “NSStringDrawingOptions”.

context

A context object with information about how to adjust the font tracking and scaling information. On return, the specified object contains information about the actual values used to render the string. This parameter may be nil.

Return Value

A rectangle whose size component indicates the width and height required to draw the entire contents of the string.

Discussion

You can use this method to compute the space required to draw the string. The constraints you specify in the size parameter are a guide for the renderer for how to size the string. However, the actual bounding rectangle returned by this method can be larger than the constraints if additional space is needed to render the entire string. Typically, the renderer preserves the width constraint and adjusts the height constraint as needed.

In iOS 7 and later, this method returns fractional sizes (in the size component of the returned CGRect); to use a returned size to size views, you must use raise its value to the nearest higher integer using the ceil function.

Special Considerations

To calculate the bounding rectangle, this method uses the baseline origin by default, so it behaves as a single line. To render the string in multiple lines, specify NSStringDrawingUsesLineFragmentOrigin in options.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

dataFromRange:documentAttributes:error:

Returns an data object that contains a text stream corresponding to the characters and attributes within the given range.

- (NSData *)dataFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error
Parameters
range

The range.

dict

A required dictionary specifying the document attributes. The dictionary contains values from “Document Types” and must at least contain NSDocumentTypeDocumentAttribute.

error

An in-out variable containing an encountered error, if any.

Return Value

Returns the data for the attributed string, or nil if failure. When nil, error encapsulates the error information.

Discussion

Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

drawAtPoint:

Draws the attributed string starting at the specified point in the current graphics context.

- (void)drawAtPoint:(CGPoint)point
Parameters
point

The point in the current graphics context where you want to start drawing the string. The coordinate system of the graphics context is usually defined by the view in which you are drawing.

Discussion

This method draws the entire string starting at the specified point. This method draws the line using the attributes specified in the attributed string itself. If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

drawInRect:

Draws the attributed string inside the specified bounding rectangle in the current graphics context.

- (void)drawInRect:(CGRect)rect
Parameters
rect

The bounding rectangle in which to draw the string.

Discussion

This method draws as much of the string as it can inside the specified rectangle, wrapping the string text as needed to make it fit. If the string is too long to fit inside the rectangle, the method renders as much as possible and clips the rest.

This method draws the line using the attributes specified in the attributed string itself. If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

drawWithRect:options:context:

Draws the attributed string in the specified bounding rectangle using the provided options.

- (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
Parameters
rect

The bounding rectangle in which to draw the string.

options

Additional drawing options to apply to the string during rendering. For a list of possible values, see “NSStringDrawingOptions”.

context

A context object with information about how to adjust the font tracking and scaling information. On return, the specified object contains information about the actual values used to render the string. This parameter may be nil.

Discussion

This method draws as much of the string as it can inside the specified rectangle. If NSStringDrawingUsesLineFragmentOrigin is specified in options, it wraps the string text as needed to make it fit. If the string is too big to fit completely inside the rectangle, the method scales the font or adjusts the letter spacing to make the string fit within the given bounds.

This method draws the line using the attributes specified in the attributed string itself. If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

Special Considerations

This method uses the baseline origin by default, so it renders the string as a single line. To render the string in multiple lines, specify NSStringDrawingUsesLineFragmentOrigin in options.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

fileWrapperFromRange:documentAttributes:error:

Returns an NSFileWrapper object that contains a text stream corresponding to the characters and attributes within the given range.

- (NSFileWrapper *)fileWrapperFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error
Parameters
range

The range.

dict

A required dictionary specifying the document attributes. The dictionary contains values from “Document Types” and must at least contain NSDocumentTypeDocumentAttribute.

error

An in-out variable containing an encountered error, if any.

Return Value

Returns a file wrapper for the appropriate document type, or nil if failure. When nil, error encapsulates the error information.

Discussion

Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

initWithData:options:documentAttributes:error:

Initializes and returns a new attributed string object from the data contained in the given data object.

- (id)initWithData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error
Parameters
data

The data from which to create the string.

options

Document attributes for interpreting the document contents. NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported option keys. If not specified, the method examines the data to attempt to determine the appropriate attributes.

dict

If non-NULL, returns a dictionary with various document-wide attributes accessible via document attribute keys.

error

An in-out variable containing an encountered error, if any.

Return Value

Returns an initialized attributed string object, or nil if the data can’t be decoded.

Discussion

The HTML importer should not be called from a background thread (that is, the options dictionary includes NSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

initWithFileURL:options:documentAttributes:error:

Initializes a new attributed string object from the data at the given URL.

- (id)initWithFileURL:(NSURL *)url options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error
Parameters
url

An NSURL object specifying the document to load.

options

Document attributes for interpreting the document contents. NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported option keys. If not specified, the method examines the data to attempt to determine the appropriate attributes.

dict

If non-NULL, returns a dictionary with various document-wide attributes accessible via document attribute keys.

error

An in-out variable containing an encountered error, if any.

Return Value

Returns an initialized attributed string object, or nil if the data can’t be decoded.

Discussion

The HTML importer should not be called from a background thread (that is, the options dictionary includes NSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

size

Returns the size required to draw the string.

- (CGSize)size
Return Value

The minimum size required to draw the entire contents of the string.

Discussion

You can use this method prior to drawing to compute how much space is required to draw the string.

In iOS 7 and later, this method returns fractional sizes; to use a returned size to size views, you must use raise its value to the nearest higher integer using the ceil function.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

Constants

String Drawing Options

Options for customizing the way strings are drawn.

enum {
   NSStringDrawingTruncatesLastVisibleLine = 1 << 5,
   NSStringDrawingUsesLineFragmentOrigin = 1 << 0,
   NSStringDrawingUsesFontLeading = 1 << 1,
   NSStringDrawingUsesDeviceMetrics = 1 << 3,
};
typedef NSInteger NSStringDrawingOptions;
Constants
NSStringDrawingTruncatesLastVisibleLine

Truncate and add an ellipsis character to the last visible line if the text does not fit into the specified bounds. This option is ignored if the NSStringDrawingUsesLineFragmentOrigin option is not also specified.

Available in iOS 6.0 and later.

Declared in NSStringDrawing.h.

NSStringDrawingUsesLineFragmentOrigin

The origin specified when drawing the string is the line fragment origin and not the baseline origin.

Available in iOS 6.0 and later.

Declared in NSStringDrawing.h.

NSStringDrawingUsesFontLeading

Use the font leading information to calculate line heights.

Available in iOS 6.0 and later.

Declared in NSStringDrawing.h.

NSStringDrawingUsesDeviceMetrics

Use the image glyph bounds (instead of the typographic bounds) when computing layout.

Available in iOS 6.0 and later.

Declared in NSStringDrawing.h.

Underline and Strikethrough Style Attributes

Constants for specifying both the NSUnderlineStyleAttributeName and NSStrikethroughStyleAttributeName attributes of an attributed string.

typedef enum : NSInteger {
   NSUnderlineStyleNone = 0x00,
   NSUnderlineStyleSingle = 0x01,
   NSUnderlineStyleThick = 0x02,
   NSUnderlineStyleDouble = 0x09,
   NSUnderlinePatternSolid = 0x0000,
   NSUnderlinePatternDot = 0x0100,
   NSUnderlinePatternDash = 0x0200,
   NSUnderlinePatternDashDot = 0x0300,
   NSUnderlinePatternDashDotDot = 0x0400,
   NSUnderlineByWord = 0x8000
} NSUnderlineStyle;
Constants
NSUnderlineStyleNone

Do not draw a line.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSUnderlineStyleSingle

Draw a single line.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSUnderlineStyleThick

Draw a thick line.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlineStyleDouble

Draw a double line.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlinePatternSolid

Draw a solid line.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlinePatternDot

Draw a line of dots.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlinePatternDash

Draw a line of dashes.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlinePatternDashDot

Draw a line of alternating dashes and dots.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlinePatternDashDotDot

Draw a line of alternating dashes and two dots.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlineByWord

Draw the line only underneath or through words, not whitespace.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

Discussion

The style, pattern, and optionally by-word mask are OR'd together to produce the value for NSUnderlineStyleAttributeName and NSStrikethroughStyleAttributeName.

Character Attributes

Attributes that you can apply to text in an attributed string.

NSString *const NSFontAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSLigatureAttributeName;
NSString *const NSKernAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSUnderlineStyleAttributeName;
NSString *const NSStrokeColorAttributeName;
NSString *const NSStrokeWidthAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSTextEffectAttributeName;
NSString *const NSAttachmentAttributeName;
NSString *const NSLinkAttributeName;
NSString *const NSBaselineOffsetAttributeName;
NSString *const NSUnderlineColorAttributeName;
NSString *const NSStrikethroughColorAttributeName;
NSString *const NSObliquenessAttributeName;
NSString *const NSExpansionAttributeName;
NSString *const NSWritingDirectionAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;
Constants
NSFontAttributeName

The value of this attribute is a UIFont object. Use this attribute to change the font for a range of text. If you do not specify this attribute, the string uses a 12-point Helvetica(Neue) font by default.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSParagraphStyleAttributeName

The value of this attribute is an NSParagraphStyle object. Use this attribute to apply multiple attributes to a range of text. If you do not specify this attribute, the string uses the default paragraph attributes, as returned by the defaultParagraphStyle method of NSParagraphStyle.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSForegroundColorAttributeName

The value of this attribute is a UIColor object. Use this attribute to specify the color of the text during rendering. If you do not specify this attribute, the text is rendered in black.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSBackgroundColorAttributeName

The value of this attribute is a UIColor object. Use this attribute to specify the color of the background area behind the text. If you do not specify this attribute, no background color is drawn.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSLigatureAttributeName

The value of this attribute is an NSNumber object containing an integer. Ligatures cause specific character combinations to be rendered using a single custom glyph that corresponds to those characters. The value 0 indicates no ligatures. The value 1 indicates the use of the default ligatures. The value 2 indicates the use of all ligatures. The default value for this attribute is 1. (Value 2 is unsupported on iOS.)

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSKernAttributeName

The value of this attribute is an NSNumber object containing a floating-point value. This value specifies the number of points by which to adjust kern-pair characters. Kerning prevents unwanted space from occurring between specific characters and depends on the font. The value 0 means kerning is disabled. The default value for this attribute is 0.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSStrikethroughStyleAttributeName

The value of this attribute is an NSNumber object containing an integer. This value indicates whether the text has a line through it and corresponds to one of the constants described in “Underline and Strikethrough Style Attributes”. The default value for this attribute is NSUnderlineStyleNone.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSUnderlineStyleAttributeName

The value of this attribute is an NSNumber object containing an integer. This value indicates whether the text is underlined and corresponds to one of the constants described in “Underline and Strikethrough Style Attributes”. The default value for this attribute is NSUnderlineStyleNone.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSStrokeColorAttributeName

The value of this parameter is a UIColor object. If it is not defined (which is the case by default), it is assumed to be the same as the value of NSForegroundColorAttributeName; otherwise, it describes the outline color. For more details, see Drawing attributed strings that are both filled and stroked.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSStrokeWidthAttributeName

The value of this attribute is an NSNumber object containing a floating-point value. This value represents the amount to change the stroke width and is specified as a percentage of the font point size. Specify 0 (the default) for no additional changes. Specify positive values to change the stroke width alone. Specify negative values to stroke and fill the text. For example, a typical value for outlined text would be 3.0.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSShadowAttributeName

The value of this attribute is an NSShadow object. The default value of this property is nil.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

NSTextEffectAttributeName

The value of this attribute is an NSString object. Use this attribute to specify a text effect, such as NSTextEffectLetterpressStyle. The default value of this property is nil, indicating no text effect.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSAttachmentAttributeName

The value of this attribute is an NSTextAttachment object. The default value of this property is nil, indicating no attachment.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSLinkAttributeName

The value of this attribute is and NSURL object (preferred) or an NSString object. The default value of this property is nil, indicating no link.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSBaselineOffsetAttributeName

The value of this attribute is an NSNumber object containing a floating point value indicating the character’s offset from the baseline, in points. The default value is 0.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSUnderlineColorAttributeName

The value of this attribute is a UIColor object. The default value is nil, indicating same as foreground color.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSStrikethroughColorAttributeName

The value of this attribute is a UIColor object. The default value is nil, indicating same as foreground color.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSObliquenessAttributeName

The value of this attribute is an NSNumber object containing a floating point value indicating skew to be applied to glyphs. The default value is 0, indicating no skew.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSExpansionAttributeName

The value of this attribute is an NSNumber object containing a floating point value indicating the log of the expansion factor to be applied to glyphs. The default value is 0, indicating no expansion.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSWritingDirectionAttributeName

The value of this attribute is an NSArray of NSNumber objects representing the nested levels of writing direction overrides, in order from outermost to innermost.

This attribute provides a means to override the default bidirectional text algorithm, equivalent to using the Unicode bidi control characters LRE, RLE, LRO, or RLO paired with PDF, but as a higher-level attribute. (See Unicode Standard Annex #9 for information about the Unicode bidi formatting codes.) The NSWritingDirectionAttributeName constant is a character-level attribute that provides a higher-level alternative to the inclusion of explicit bidirectional control characters in text. It is the NSAttributedString equivalent of the HTML markup using bdo element with the dir attribute.

The values of the NSNumber objects should be 0, 1, 2, or 3, for LRE, RLE, LRO, or RLO respectively, and combinations of NSWritingDirectionLeftToRight and NSWritingDirectionRightToLeft with NSTextWritingDirectionEmbedding or NSTextWritingDirectionOverride, as shown in “Values of NSWritingDirectionAttributeName and equivalent markup.”

Table 1  Values of NSWritingDirectionAttributeName and equivalent markup

Array NSNumber Values

Unicode Control Characters

Writing Direction Constants

0

LRE

NSWritingDirectionLeftToRight | NSTextWritingDirectionEmbedding

1

RLE

NSWritingDirectionRightToLeft | NSTextWritingDirectionEmbedding

2

LRO

NSWritingDirectionLeftToRight | NSTextWritingDirectionOverride

3

RLO

NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSVerticalGlyphFormAttributeName

The value of this attribute is an NSNumber object containing an integer. The value 0 indicates horizontal text. The value 1 indicates vertical text. In iOS, horizontal text is always used and specifying a different value is undefined.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

Text Writing Direction

Options for specifying text writing direction used with NSWritingDirectionAttributeName.

typedef enum : NSInteger {
   NSTextWritingDirectionEmbedding     = (0 << 1),
   NSTextWritingDirectionOverride      = (1 << 1)
} NSTextWritingDirection;
Constants
NSTextWritingDirectionEmbedding

Text is embedded in text with another writing direction. For example, an English quotation in the middle of an Arabic sentence could be marked as being embedded left-to-right text.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSTextWritingDirectionOverride

Enables character types with inherent directionality to be overridden when required for special cases, such as for part numbers made of mixed English, digits, and Hebrew letters to be written from right to left.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

Discussion

You can use the logical OR operator to combine these constants with NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft when used with NSWritingDirectionAttributeName to specify formatting controls defined by the Unicode Bidirectional Algorithm in Unicode Standard Annex #9.

Document Types

The following values can be returned for the NSDocumentTypeDocumentAttribute key in the document attributes dictionary.

NSString *NSPlainTextDocumentType;
NSString *NSRTFTextDocumentType;
NSString *NSRTFDTextDocumentType;
NSString *NSHTMLTextDocumentType;
Constants
NSPlainTextDocumentType

Plain text document.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSRTFTextDocumentType

Rich text format document.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSRTFDTextDocumentType

Rich text format with attachments document.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSHTMLTextDocumentType

Hypertext Markup Language (HTML) document.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

Keys for Options and Document Attributes Dictionaries

These keys represent in and out document properties used by both read and write methods.

NSString *const NSDocumentTypeDocumentAttribute;
NSString *const NSCharacterEncodingDocumentAttribute;
NSString *const NSDefaultAttributesDocumentAttribute;
NSString *const NSPaperSizeDocumentAttribute;
NSString *const NSPaperMarginDocumentAttribute;
NSString *const NSViewSizeDocumentAttribute;
NSString *const NSViewZoomDocumentAttribute;
NSString *const NSViewModeDocumentAttribute;
NSString *const NSReadOnlyDocumentAttribute;
NSString *const NSBackgroundColorDocumentAttribute;
NSString *const NSHyphenationFactorDocumentAttribute;
NSString *const NSDefaultTabIntervalDocumentAttribute;
NSString *const NSTextLayoutSectionsAttribute;
Constants
NSDocumentTypeDocumentAttribute

@"DocumentType", one of the document types declared in “Document Types.” For reader methods, this key in options can specify the document type for interpreting the contents. Upon return, the document attributes can contain this key for indicating the actual format used to read the contents. For write methods, this key specifies the format for generating the data.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSCharacterEncodingDocumentAttribute

@"CharacterEncoding", NSNumber containing integer specifying NSStringEncoding for the file; default for plain text is the default encoding. This key in options can specify the string encoding for reading the data. Upon return, the document attributes can contain the actual encoding used. For writing methods, this value is used for generating the plain text data.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSDefaultAttributesDocumentAttribute

@"DefaultAttributes", NSDictionary containing attributes to be applied to plain files. Used by reader methods. This key in options can specify the default attributes applied to the entire document contents. Upon return, the document attributes can contain this key indicating the actual attributes used.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSPaperSizeDocumentAttribute

@"PaperSize", NSValue containing CGSize (in points).

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSPaperMarginDocumentAttribute

@"PaperMargin", NSValue containing UIEdgeInsets.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSViewSizeDocumentAttribute

@"ViewSize", NSValue containing CGSize (in points).

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSViewZoomDocumentAttribute

@"ViewZoom", NSNumber containing floating point value: 100 = 100% zoom.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSViewModeDocumentAttribute

@"ViewMode", NSNumber containing integer: 0 = normal; 1 = page layout.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSReadOnlyDocumentAttribute

@"ReadOnly", NSNumber containing integer: if missing, 0 or negative = not readonly; 1 or more = readonly. This attribute has nothing to do with the file system protection on the file; instead, it indicates how the file should be displayed to the user.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSBackgroundColorDocumentAttribute

@"BackgroundColor", UIColor representing the document-wide page background color.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSHyphenationFactorDocumentAttribute

@"HyphenationFactor", NSNumber containing floating point value: 0 = off; 1 = full hyphenation.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSDefaultTabIntervalDocumentAttribute

@"DefaultTabInterval", NSNumber containing floating point value representing the document-wide default tab stop interval, in points.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSTextLayoutSectionsAttribute

An NSArray containing NSDictionary objects, each dictionary describing a layout orientation section. The dictionary can have two attributes: NSTextLayoutSectionOrientation and NSTextLayoutSectionRange. When there is a gap between sections, it's assumed to have NSTextLayoutOrientationHorizontal.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

Text Layout Sections Attribute

These constants are used by NSTextLayoutSectionsAttribute.

NSString *NSTextLayoutSectionOrientation;
NSString *NSTextLayoutSectionRange;
Constants
NSTextLayoutSectionOrientation

An NSNumber containing an NSTextLayoutOrientation value. The default value is NSTextLayoutOrientationHorizontal.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

NSTextLayoutSectionRange

An NSValue containing an NSRange representing a character range. The default value is a range covering the entire string.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.

Text Effect Attribute

This constant is used by NSTextEffectAttributeName.

NSString *const NSTextEffectLetterpressStyle;
Constants
NSTextEffectLetterpressStyle

A graphical text effect giving glyphs the appearance of letterpress printing, in which type is pressed into the paper.

Available in iOS 7.0 and later.

Declared in NSAttributedString.h.