iOS Developer Library

Developer

UIKit Framework Reference NSAttributedString UIKit Additions Reference

Options
Deployment Target:

On This Page
Language:

NSAttributedString

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.

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.

  • Creates an attributed string with an attachment.

    Declaration

    Swift

    init(attachment attachment: NSTextAttachment) -> NSAttributedString

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    init?(data data: NSData, options options: [NSObject : AnyObject]?, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>, error error: NSErrorPointer)

    Objective-C

    - (instancetype)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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    init?(fileURL url: NSURL!, options options: [NSObject : AnyObject]!, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>, error error: NSErrorPointer)

    Objective-C

    - (instancetype)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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func drawAtPoint(_ point: CGPoint)

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func drawInRect(_ rect: CGRect)

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func drawWithRect(_ rect: CGRect, options options: NSStringDrawingOptions, context context: NSStringDrawingContext?)

    Objective-C

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

    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.

    If NSStringDrawingUsesLineFragmentOrigin is not specified in options, the origin of the rectangle is the baseline of the only line. The text will be displayed above the rectangle and not inside of it. For example, if you specify a rectangle starting at 0,0 and draw the string ‘juxtaposed’, only the descenders of the ‘j’ and ‘p’ will be seen. The rest of the text will be on the top edge of the rectangle.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Returns the size required to draw the string.

    Declaration

    Swift

    func size() -> CGSize

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Returns the bounding rectangle required to draw the string.

    Declaration

    Swift

    func boundingRectWithSize(_ size: CGSize, options options: NSStringDrawingOptions, context context: NSStringDrawingContext?) -> CGRect

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func dataFromRange(_ range: NSRange, documentAttributes dict: [NSObject : AnyObject], error error: NSErrorPointer) -> NSData?

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func fileWrapperFromRange(_ range: NSRange, documentAttributes dict: [NSObject : AnyObject], error error: NSErrorPointer) -> NSFileWrapper?

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Options for customizing the way strings are drawn.

    Declaration

    Swift

    struct NSStringDrawingOptions : RawOptionSetType { init(_ rawValue: Int) init(rawValue rawValue: Int) static var TruncatesLastVisibleLine: NSStringDrawingOptions { get } static var UsesLineFragmentOrigin: NSStringDrawingOptions { get } static var UsesFontLeading: NSStringDrawingOptions { get } static var UsesDeviceMetrics: NSStringDrawingOptions { get } }

    Objective-C

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

    Constants

    • TruncatesLastVisibleLine

      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.

    • UsesLineFragmentOrigin

      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.

    • UsesFontLeading

      NSStringDrawingUsesFontLeading

      Use the font leading information to calculate line heights.

      Available in iOS 6.0 and later.

    • UsesDeviceMetrics

      NSStringDrawingUsesDeviceMetrics

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

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    enum NSUnderlineStyle : Int { case StyleNone case StyleSingle case StyleThick case StyleDouble case PatternDot case PatternDash case PatternDashDot case PatternDashDotDot case ByWord }

    Objective-C

    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

    • StyleNone

      NSUnderlineStyleNone

      Do not draw a line.

      Available in iOS 6.0 and later.

    • StyleSingle

      NSUnderlineStyleSingle

      Draw a single line.

      Available in iOS 6.0 and later.

    • StyleThick

      NSUnderlineStyleThick

      Draw a thick line.

      Available in iOS 7.0 and later.

    • StyleDouble

      NSUnderlineStyleDouble

      Draw a double line.

      Available in iOS 7.0 and later.

    • NSUnderlinePatternSolid

      NSUnderlinePatternSolid

      Draw a solid line.

      Available in iOS 7.0 and later.

    • PatternDot

      NSUnderlinePatternDot

      Draw a line of dots.

      Available in iOS 7.0 and later.

    • PatternDash

      NSUnderlinePatternDash

      Draw a line of dashes.

      Available in iOS 7.0 and later.

    • PatternDashDot

      NSUnderlinePatternDashDot

      Draw a line of alternating dashes and dots.

      Available in iOS 7.0 and later.

    • PatternDashDotDot

      NSUnderlinePatternDashDotDot

      Draw a line of alternating dashes and two dots.

      Available in iOS 7.0 and later.

    • ByWord

      NSUnderlineByWord

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

      Available in iOS 7.0 and later.

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    let NSFontAttributeName: String let NSParagraphStyleAttributeName: String let NSForegroundColorAttributeName: String let NSBackgroundColorAttributeName: String let NSLigatureAttributeName: String let NSKernAttributeName: String let NSStrikethroughStyleAttributeName: String let NSUnderlineStyleAttributeName: String let NSStrokeColorAttributeName: String let NSStrokeWidthAttributeName: String let NSShadowAttributeName: String let NSTextEffectAttributeName: String let NSAttachmentAttributeName: String let NSLinkAttributeName: String let NSBaselineOffsetAttributeName: String let NSUnderlineColorAttributeName: String let NSStrikethroughColorAttributeName: String let NSObliquenessAttributeName: String let NSExpansionAttributeName: String let NSWritingDirectionAttributeName: String let NSVerticalGlyphFormAttributeName: String

    Objective-C

    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

      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.

    • NSParagraphStyleAttributeName

      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.

    • NSForegroundColorAttributeName

      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.

    • NSBackgroundColorAttributeName

      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.

    • NSLigatureAttributeName

      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.

    • NSKernAttributeName

      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.

    • NSStrikethroughStyleAttributeName

      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.

    • NSUnderlineStyleAttributeName

      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.

    • NSStrokeColorAttributeName

      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.

    • NSStrokeWidthAttributeName

      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.

    • NSShadowAttributeName

      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.

    • NSTextEffectAttributeName

      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.

    • NSAttachmentAttributeName

      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.

    • NSLinkAttributeName

      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.

    • NSBaselineOffsetAttributeName

      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.

    • NSUnderlineColorAttributeName

      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.

    • NSStrikethroughColorAttributeName

      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.

    • NSObliquenessAttributeName

      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.

    • NSExpansionAttributeName

      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.

    • NSWritingDirectionAttributeName

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

    • NSVerticalGlyphFormAttributeName

      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.

  • Options for specifying text writing direction used with NSWritingDirectionAttributeName.

    Declaration

    Swift

    enum NSTextWritingDirection : Int { case Embedding case Override }

    Objective-C

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

    Constants

    • Embedding

      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.

    • Override

      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.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    let NSPlainTextDocumentType: String let NSRTFTextDocumentType: String let NSRTFDTextDocumentType: String let NSHTMLTextDocumentType: String

    Objective-C

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

    Constants

    • NSPlainTextDocumentType

      NSPlainTextDocumentType

      Plain text document.

      Available in iOS 7.0 and later.

    • NSRTFTextDocumentType

      NSRTFTextDocumentType

      Rich text format document.

      Available in iOS 7.0 and later.

    • NSRTFDTextDocumentType

      NSRTFDTextDocumentType

      Rich text format with attachments document.

      Available in iOS 7.0 and later.

    • NSHTMLTextDocumentType

      NSHTMLTextDocumentType

      Hypertext Markup Language (HTML) document.

      Available in iOS 7.0 and later.

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

    Declaration

    Swift

    let NSDocumentTypeDocumentAttribute: String let NSCharacterEncodingDocumentAttribute: String let NSDefaultAttributesDocumentAttribute: String let NSPaperSizeDocumentAttribute: String let NSPaperMarginDocumentAttribute: String let NSViewSizeDocumentAttribute: String let NSViewZoomDocumentAttribute: String let NSViewModeDocumentAttribute: String let NSReadOnlyDocumentAttribute: String let NSBackgroundColorDocumentAttribute: String let NSHyphenationFactorDocumentAttribute: String let NSDefaultTabIntervalDocumentAttribute: String let NSTextLayoutSectionsAttribute: String

    Objective-C

    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

      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.

    • NSCharacterEncodingDocumentAttribute

      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.

    • NSDefaultAttributesDocumentAttribute

      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.

    • NSPaperSizeDocumentAttribute

      NSPaperSizeDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSPaperMarginDocumentAttribute

      NSPaperMarginDocumentAttribute

      @"PaperMargin", NSValue containing UIEdgeInsets.

      Available in iOS 7.0 and later.

    • NSViewSizeDocumentAttribute

      NSViewSizeDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSViewZoomDocumentAttribute

      NSViewZoomDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSViewModeDocumentAttribute

      NSViewModeDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSReadOnlyDocumentAttribute

      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.

    • NSBackgroundColorDocumentAttribute

      NSBackgroundColorDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSHyphenationFactorDocumentAttribute

      NSHyphenationFactorDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSDefaultTabIntervalDocumentAttribute

      NSDefaultTabIntervalDocumentAttribute

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

      Available in iOS 7.0 and later.

    • NSTextLayoutSectionsAttribute

      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.

  • These constants are used by NSTextLayoutSectionsAttribute.

    Declaration

    Swift

    let NSTextLayoutSectionOrientation: String let NSTextLayoutSectionRange: String

    Objective-C

    NSString *NSTextLayoutSectionOrientation; NSString *NSTextLayoutSectionRange;

    Constants

    • NSTextLayoutSectionOrientation

      NSTextLayoutSectionOrientation

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

      Available in iOS 7.0 and later.

    • NSTextLayoutSectionRange

      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.

  • This constant is used by NSTextEffectAttributeName.

    Declaration

    Swift

    let NSTextEffectLetterpressStyle: String

    Objective-C

    NSString *const NSTextEffectLetterpressStyle;

    Constants

    • NSTextEffectLetterpressStyle

      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.