iOS Developer Library

Developer

ApplicationServices Framework Reference Core Text String Attributes Reference

Options
Deployment Target:

On This Page
Language:

Core Text String Attributes Reference

This reference document describes the attributes to which Core Text responds when the attributes are placed in a CFAttributedString object.

Constants

  • These constants represent string attribute names.

    Declaration

    Swift

    let kCTCharacterShapeAttributeName: CFString! let kCTFontAttributeName: CFString! let kCTKernAttributeName: CFString! let kCTLigatureAttributeName: CFString! let kCTForegroundColorAttributeName: CFString! let kCTForegroundColorFromContextAttributeName: CFString! let kCTParagraphStyleAttributeName: CFString! let kCTStrokeWidthAttributeName: CFString! let kCTStrokeColorAttributeName: CFString! let kCTSuperscriptAttributeName: CFString! let kCTUnderlineColorAttributeName: CFString! let kCTUnderlineStyleAttributeName: CFString! let kCTVerticalFormsAttributeName: CFString! let kCTGlyphInfoAttributeName: CFString! let kCTRunDelegateAttributeName: CFString!

    Objective-C

    const CFStringRef kCTCharacterShapeAttributeName; const CFStringRef kCTFontAttributeName; const CFStringRef kCTKernAttributeName; const CFStringRef kCTLigatureAttributeName; const CFStringRef kCTForegroundColorAttributeName; const CFStringRef kCTForegroundColorFromContextAttributeName; const CFStringRef kCTParagraphStyleAttributeName; const CFStringRef kCTStrokeWidthAttributeName; const CFStringRef kCTStrokeColorAttributeName; const CFStringRef kCTSuperscriptAttributeName; const CFStringRef kCTUnderlineColorAttributeName; const CFStringRef kCTUnderlineStyleAttributeName; const CFStringRef kCTVerticalFormsAttributeName; const CFStringRef kCTGlyphInfoAttributeName; const CFStringRef kCTRunDelegateAttributeName

    Constants

    • kCTCharacterShapeAttributeName

      kCTCharacterShapeAttributeName

      Controls glyph selection. Value must be a CFNumberRef object. Default is value is 0 (disabled). A non-zero value is interpreted as Apple Type Services kCharacterShapeType selector + 1 (see <ATS/SFNTLayoutTypes.h> for selectors). For example, an attribute value of 1 corresponds to kTraditionalCharactersSelector.

      Available in iOS 3.2 and later.

    • kCTFontAttributeName

      kCTFontAttributeName

      The font of the text to which this attribute applies. The value associated with this attribute must be a CTFont object. Default is Helvetica 12.

      Available in iOS 3.2 and later.

    • kCTKernAttributeName

      kCTKernAttributeName

      The amount to kern the next character. The value associated with this attribute must be a CFNumber float. Default is standard kerning. The kerning attribute indicates how many points the following character should be shifted from its default offset as defined by the current character's font in points: a positive kern indicates a shift farther away from and a negative kern indicates a shift closer to the current character. If this attribute is not present, standard kerning is used. If this attribute is set to 0.0, no kerning is done at all.

      Available in iOS 3.2 and later.

    • kCTLigatureAttributeName

      kCTLigatureAttributeName

      The type of ligatures to use. The value associated with this attribute must be a CFNumber object. Default is an integer value of 1. The ligature attribute determines what kinds of ligatures should be used when displaying the string. A value of 0 indicates that only ligatures essential for proper rendering of text should be used. A value of 1 indicates that standard ligatures should be used, and 2 indicates that all available ligatures should be used. Which ligatures are standard depends on the script and possibly the font. Arabic text, for example, requires ligatures for many character sequences but has a rich set of additional ligatures that combine characters. English text has no essential ligatures, and typically has only two standard ligatures, those for "fi" and "fl"—all others are considered more advanced or fancy.

      Available in iOS 3.2 and later.

    • kCTForegroundColorAttributeName

      kCTForegroundColorAttributeName

      The foreground color of the text to which this attribute applies. The value associated with this attribute must be a CGColor object. Default value is black.

      Available in iOS 3.2 and later.

    • kCTForegroundColorFromContextAttributeName

      kCTForegroundColorFromContextAttributeName

      Sets a foreground color using the context's fill color. Value must be a CFBooleanRef object. Default is false. The reason this exists is because an NSAttributedString object defaults to a black color if no color attribute is set. This forces Core Text to set the color in the context. This attribute allows developers to sidestep this, making Core Text set nothing but font information in the CGContext. If set, this attribute also determines the color used by kCTUnderlineStyleAttributeName, in which case it overrides the foreground color.

      Available in iOS 3.2 and later.

    • kCTParagraphStyleAttributeName

      kCTParagraphStyleAttributeName

      The paragraph style of the text to which this attribute applies. A paragraph style object is used to specify things like line alignment, tab rulers, writing direction, and so on. Value must be a CTParagraphStyle object. Default is an empty CTParagraphStyle object. See CTParagraphStyle Reference for more information.

      Available in iOS 3.2 and later.

    • kCTStrokeWidthAttributeName

      kCTStrokeWidthAttributeName

      The stroke width. Value must be a CFNumberRef object. Default value is 0.0, or no stroke. This attribute, interpreted as a percentage of font point size, controls the text drawing mode: positive values effect drawing with stroke only; negative values are for stroke and fill. A typical value for outlined text is 3.0.

      Available in iOS 3.2 and later.

    • kCTStrokeColorAttributeName

      kCTStrokeColorAttributeName

      The stroke color. Value must be a CGColorRef object. Default is the foreground color.

      Available in iOS 3.2 and later.

    • kCTSuperscriptAttributeName

      kCTSuperscriptAttributeName

      Controls vertical text positioning. Value must be a CFNumberRef object. Default is integer value 0. If supported by the specified font, a value of 1 enables superscripting and a value of -1 enables subscripting.

      Available in iOS 3.2 and later.

    • kCTUnderlineColorAttributeName

      kCTUnderlineColorAttributeName

      The underline color. Value must be a CGColorRef object. Default is the foreground color.

      Available in iOS 3.2 and later.

    • kCTUnderlineStyleAttributeName

      kCTUnderlineStyleAttributeName

      The style of underlining, to be applied at render time, for the text to which this attribute applies. Value must be a CFNumber object. Default is kCTUnderlineStyleNone. Set a value of something other than kCTUnderlineStyleNone to draw an underline. In addition, the constants listed in CTUnderlineStyleModifiers can be used to modify the look of the underline. The underline color is determined by the text's foreground color.

      Available in iOS 3.2 and later.

    • kCTVerticalFormsAttributeName

      kCTVerticalFormsAttributeName

      The orientation of the glyphs in the text to which this attribute applies. Value must be a CFBoolean object. Default is False. A value of False indicates that horizontal glyph forms are to be used; True indicates that vertical glyph forms are to be used.

      Available in iOS 4.3 and later.

    • kCTGlyphInfoAttributeName

      kCTGlyphInfoAttributeName

      The glyph info object to apply to the text associated with this attribute. Value must be a CTGlyphInfo object. The glyph specified by this CTGlyphInfo object is assigned to the entire attribute range, provided that its contents match the specified base string and that the specified glyph is available in the font specified by kCTFontAttributeName. See CTGlyphInfo Reference for more information.

      Available in iOS 3.2 and later.

    • kCTRunDelegateAttributeName

      kCTRunDelegateAttributeName

      The run-delegate object to apply to an attribute range of the string. The value must be a CTRunDelegate object. The run delegate controls such typographic traits as glyph ascent, descent, and width. The values returned by the embedded run delegate apply to each glyph resulting from the text in that range. Because an embedded object is only a display-time modification, you should avoid applying this attribute to a range of text with complex behavior, such as text having a change of writing direction or having combining marks. It is thus recommended you apply this attribute to a range containing the single character U+FFFC. See CTRunDelegate Reference for more information.

      Available in iOS 3.2 and later.

  • Underline style specifiers.

    Declaration

    Swift

    struct CTUnderlineStyle : RawOptionSetType { init(_ rawValue: Int32) init(rawValue rawValue: Int32) static var None: CTUnderlineStyle { get } static var Single: CTUnderlineStyle { get } static var Thick: CTUnderlineStyle { get } static var Double: CTUnderlineStyle { get } }

    Objective-C

    enum{ kCTUnderlineStyleNone = 0x00, kCTUnderlineStyleSingle = 0x01, kCTUnderlineStyleThick = 0x02, kCTUnderlineStyleDouble = 0x09 }; typedef int32_t CTUnderlineStyle;

    Constants

    • None

      kCTUnderlineStyleNone

      Do not draw an underline.

      Available in iOS 3.2 and later.

    • Single

      kCTUnderlineStyleSingle

      Draw an underline consisting of a single line.

      Available in iOS 3.2 and later.

    • Thick

      kCTUnderlineStyleThick

      Draw an underline consisting of a thick line.

      Available in iOS 3.2 and later.

    • Double

      kCTUnderlineStyleDouble

      Draw an underline consisting of a double line.

      Available in iOS 3.2 and later.

    Discussion

    These underline type specifiers can be applied to the value set with the kCTUnderlineStyleAttributeName attribute to control the underline style Core Text uses when rendering the text to which the attribute applies.

    Import Statement

    Objective-C

    @import CoreText;

    Swift

    import CoreText

    Availability

    Available in iOS 3.2 and later.

  • Underline style modifiers.

    Declaration

    Swift

    struct CTUnderlineStyleModifiers : RawOptionSetType { init(_ rawValue: Int32) init(rawValue rawValue: Int32) static var PatternSolid: CTUnderlineStyleModifiers { get } static var PatternDot: CTUnderlineStyleModifiers { get } static var PatternDash: CTUnderlineStyleModifiers { get } static var PatternDashDot: CTUnderlineStyleModifiers { get } static var PatternDashDotDot: CTUnderlineStyleModifiers { get } }

    Objective-C

    enum{ kCTUnderlinePatternSolid = 0x0000, kCTUnderlinePatternDot = 0x0100, kCTUnderlinePatternDash = 0x0200, kCTUnderlinePatternDashDot = 0x0300, kCTUnderlinePatternDashDotDot = 0x0400 }; typedef int32_t CTUnderlineStyleModifiers;

    Constants

    • PatternSolid

      kCTUnderlinePatternSolid

      Draw a solid underline.

      Available in iOS 3.2 and later.

    • PatternDot

      kCTUnderlinePatternDot

      Draw an underline using a pattern of dots.

      Available in iOS 3.2 and later.

    • PatternDash

      kCTUnderlinePatternDash

      Draw an underline using a pattern of dashes.

      Available in iOS 3.2 and later.

    • PatternDashDot

      kCTUnderlinePatternDashDot

      Draw an underline using a pattern of alternating dashes and dots.

      Available in iOS 3.2 and later.

    • PatternDashDotDot

      kCTUnderlinePatternDashDotDot

      Draw an underline using a pattern of a dash followed by two dots.

      Available in iOS 3.2 and later.

    Discussion

    Set these bits with the underline style (see CTUnderlineStyle) that you set with the kCTUnderlineStyleAttributeName attribute to modify how the underline will be drawn.

    Import Statement

    Objective-C

    @import CoreText;

    Swift

    import CoreText

    Availability

    Available in iOS 3.2 and later.