Next Page > Hide TOC

CATextLayer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/QuartzCore.framework
Availability
Available in Mac OS X v10.5 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.

Note: CATextLayer disabled sub-pixel antialiasing when rendering text. Text can only be drawn using sub-pixel antialiasing when it is composited into an existing opaque background at the same time that it's rasterized. There is no way to draw subpixel-antialiased text by itself, whether into an image or a layer, separately in advance of having the background pixels to weave the text pixels into. Setting the opacity property of the layer to YES does not change the rendering mode.

Note: When a CATextLayer instance is positioned using the CAConstraintLayoutManager Class Reference the bounds of the layer is resized to fit the text content.

Tasks

Getting and Setting the Text

Text Visual Properties

Text Alignment and Truncation

Properties

For more about Objective-C properties, see “Properties” in The Objective-C 2.0 Programming Language.

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
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, or a string naming the font. Defaults to Helvetica.

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

Note: If the font property specifies a font size (if it is a CTFontRef, a CGFontRef, an instance of NSFont) the font size is ignored.

Availability
Declared In
CATextLayer.h

fontSize

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

@property CGFloat fontSize

Discussion

Defaults to 36.0.

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

Availability
Declared In
CATextLayer.h

foregroundColor

The color used to render the receiver’s text.

@property CGColorRef foregroundColor

Discussion

Defaults to opaque white.

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

Availability
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
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
Declared In
CATextLayer.h

wrapped

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

@property BOOL wrapped

Discussion

Defaults to NO.

Availability
See Also
Declared In
CATextLayer.h

Instance Methods

isWrapped

A synthesized accessor for the wrapped property.

- (BOOL)isWrapped

See Also

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 Mac OS X v10.5 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 Mac OS X v10.5 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 Mac OS X v10.5 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 Mac OS X v10.5 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 Mac OS X v10.5 and later.

Declared in CATextLayer.h.

kCAAlignmentLeft

Text is visually left aligned.

Available in Mac OS X v10.5 and later.

Declared in CATextLayer.h.

kCAAlignmentRight

Text is visually right aligned.

Available in Mac OS X v10.5 and later.

Declared in CATextLayer.h.

kCAAlignmentCenter

Text is visually center aligned.

Available in Mac OS X v10.5 and later.

Declared in CATextLayer.h.

kCAAlignmentJustified

Text is justified.

Available in Mac OS X v10.5 and later.

Declared in CATextLayer.h.

Declared In
CATextLayer.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.