Mac Developer Library

Developer

QuartzCore Framework Reference CATextLayer Class Reference

Options
Deployment Target:

On This Page
Language:

CATextLayer

Inheritance


Import Statement


Swift

import QuartzCore

Objective-C

@import QuartzCore;

Availability


Available in OS X v10.5 and later.

The CATextLayer provides simple text layout and rendering of plain or attributed strings. The first line is aligned to the top of the layer.

  • string string Property

    The text to be rendered by the receiver.

    Declaration

    Swift

    @NSCopying var string: AnyObject!

    Objective-C

    @property(copy) id string

    Discussion

    The text must be an instance of NSString or NSAttributedString. Defaults to nil.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • font font Property

    The font used to render the receiver’s text.

    Declaration

    Swift

    var font: AnyObject!

    Objective-C

    @property CFTypeRef font

    Discussion

    May be either a CTFontRef, a CGFontRef, an instance of NSFont (OS X only), or a string naming the font. In iOS, you cannot assign a UIFont object to this property. Defaults to Helvetica.

    The font property is only used when the string property is not an NSAttributedString.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • fontSize fontSize Property

    The font size used to render the receiver’s text. Animatable.

    Declaration

    Swift

    var fontSize: CGFloat

    Objective-C

    @property CGFloat fontSize

    Discussion

    Defaults to 36.0.

    The fontSize property is only used when the string property is not an NSAttributedString.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • The color used to render the receiver’s text. Animatable.

    Declaration

    Swift

    var foregroundColor: CGColor!

    Objective-C

    @property CGColorRef foregroundColor

    Discussion

    Defaults to opaque white.

    The foregroundColor property is only used when the string property is not an NSAttributedString.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • wrapped wrapped Property

    Determines whether the text is wrapped to fit within the receiver’s bounds.

    Declaration

    Swift

    var wrapped: Bool

    Objective-C

    @property(getter=isWrapped) BOOL wrapped

    Discussion

    Defaults to NOfalse.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Determines how individual lines of text are horizontally aligned within the receiver’s bounds.

    Declaration

    Swift

    var alignmentMode: String!

    Objective-C

    @property(copy) NSString *alignmentMode

    Discussion

    The possible values are described in “Horizontal alignment modes”. Defaults to kCAAlignmentNatural.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Determines how the text is truncated to fit within the receiver’s bounds.

    Declaration

    Swift

    var truncationMode: String!

    Objective-C

    @property(copy) NSString *truncationMode

    Discussion

    The possible values are described in “Truncation modes”. Defaults to kCATruncationNone.

    Import Statement

    Objective-C

    @import QuartzCore;

    Swift

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • These constants are used by the truncationMode property.

    Declaration

    Swift

    let kCATruncationNone: String let kCATruncationStart: String let kCATruncationEnd: String let kCATruncationMiddle: String

    Objective-C

    NSString * const kCATruncationNone; NSString * const kCATruncationStart; NSString * const kCATruncationEnd; NSString * const kCATruncationMiddle;

    Constants

    • kCATruncationNone

      kCATruncationNone

      If the wrapped property is YEStrue, the text is wrapped to the receiver’s bounds, otherwise the text is clipped to the receiver’s bounds.

      Available in OS X v10.5 and later.

    • kCATruncationStart

      kCATruncationStart

      Each line is displayed so that the end fits in the container and the missing text is indicated by some kind of ellipsis glyph.

      Available in OS X v10.5 and later.

    • kCATruncationEnd

      kCATruncationEnd

      Each line is displayed so that the beginning fits in the container and the missing text is indicated by some kind of ellipsis glyph.

      Available in OS X v10.5 and later.

    • kCATruncationMiddle

      kCATruncationMiddle

      Each line is displayed so that the beginning and end fit in the container and the missing text is indicated by some kind of ellipsis glyph in the middle.

      Available in OS X v10.5 and later.

  • These constants are used by the alignmentMode property.

    Declaration

    Swift

    let kCAAlignmentNatural: String let kCAAlignmentLeft: String let kCAAlignmentRight: String let kCAAlignmentCenter: String let kCAAlignmentJustified: String

    Objective-C

    NSString * const kCAAlignmentNatural; NSString * const kCAAlignmentLeft; NSString * const kCAAlignmentRight; NSString * const kCAAlignmentCenter; NSString * const kCAAlignmentJustified;

    Constants

    • kCAAlignmentNatural

      kCAAlignmentNatural

      Use the natural alignment of the text’s script.

      Available in OS X v10.5 and later.

    • kCAAlignmentLeft

      kCAAlignmentLeft

      Text is visually left aligned.

      Available in OS X v10.5 and later.

    • kCAAlignmentRight

      kCAAlignmentRight

      Text is visually right aligned.

      Available in OS X v10.5 and later.

    • kCAAlignmentCenter

      kCAAlignmentCenter

      Text is visually center aligned.

      Available in OS X v10.5 and later.

    • kCAAlignmentJustified

      kCAAlignmentJustified

      Text is justified.

      Available in OS X v10.5 and later.