CATextLayer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/QuartzCore.framework
Availability
Available in iOS 3.2 and later.
Declared in
CATextLayer.h
Companion guides
Related sample code

Overview

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

Tasks

Getting and Setting the Text

Text Visual Properties

Text Alignment and Truncation

Properties

alignmentMode

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

@property(copy) NSString *alignmentMode
Discussion

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

Availability
  • Available in iOS 3.2 and later.
Related Sample Code
Declared In
CATextLayer.h

font

The font used to render the receiver’s text.

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

Availability
  • Available in iOS 3.2 and later.
Related Sample Code
Declared In
CATextLayer.h

fontSize

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

@property CGFloat fontSize
Discussion

Defaults to 36.0.

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

Availability
  • Available in iOS 3.2 and later.
Declared In
CATextLayer.h

foregroundColor

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

@property CGColorRef foregroundColor
Discussion

Defaults to opaque white.

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

Availability
  • Available in iOS 3.2 and later.
Related Sample Code
Declared In
CATextLayer.h

string

The text to be rendered by the receiver.

@property(copy) id string
Discussion

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

Availability
  • Available in iOS 3.2 and later.
Related Sample Code
Declared In
CATextLayer.h

truncationMode

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

@property(copy) NSString *truncationMode
Discussion

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

Availability
  • Available in iOS 3.2 and later.
Declared In
CATextLayer.h

wrapped

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

@property(getter=isWrapped) BOOL wrapped
Discussion

Defaults to NO.

Availability
  • Available in iOS 3.2 and later.
Declared In
CATextLayer.h

Constants

Truncation modes

These constants are used by the truncationMode property.

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

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

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

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 iOS 3.2 and later.

Declared in CATextLayer.h.

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 iOS 3.2 and later.

Declared in CATextLayer.h.

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 iOS 3.2 and later.

Declared in CATextLayer.h.

Declared In
CATextLayer.h

Horizontal alignment modes

These constants are used by the alignmentMode property.

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

Use the natural alignment of the text’s script.

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

kCAAlignmentLeft

Text is visually left aligned.

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

kCAAlignmentRight

Text is visually right aligned.

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

kCAAlignmentCenter

Text is visually center aligned.

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

kCAAlignmentJustified

Text is justified.

Available in iOS 3.2 and later.

Declared in CATextLayer.h.

Declared In
CATextLayer.h