iOS Reference Library Apple Developer
Search

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

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 disables 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: In Mac OS X, when a CATextLayer instance is positioned using the CAConstraintLayoutManager class 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 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
  • Available in iOS 3.2 and later.
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 (Mac 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.

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
  • Available in iOS 3.2 and later.
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 font property is only used when the string property is not an NSAttributedString.

Note: Implicit animation of this property is only enabled in applications compiled for Mac OS X v10.6 and later.

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.

Note: Implicit animation of this property is only enabled in applications compiled for Mac OS X v10.6 and later.

Availability
  • Available in iOS 3.2 and later.
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.
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



Last updated: 2010-05-24

Did this document help you? Yes It's good, but... Not helpful...