# CCLabelTTF Class Reference

Inherits from | CCSprite : CCNode : CCResponder : NSObject
Conforms to | CCLabelProtocol
Declared in | CCLabelTTF.h

## Overview

CCLabelTTF displays a rendered TTF font texture. The label is created from a platform font. Attributed strings are supported on Mac and iOS6+ which allows for greater text formatting control.

### Notes

Each time you modify the label text you are effectivley creating a new CCLabelTTF so there may be a performance hit if you need to frequently update the label. In this scenario you should also look at CCLabelBMFont which does not have this overhead.

### Resources

- http://iosfonts.com/ (Please use Safari for accurate font rendering)

## Tasks

### Accessing the Text Attributes

- `string` property
- `attributedString` property
- `fontName` property
- `fontSize` property
- `fontColor` property
- `horizontalAlignment` property
- `verticalAlignment` property

### Sizing the Label

- `dimensions` property
- `dimensionsType` property
- `adjustsFontSizeToFit` property
- `minimumFontSize` property
- `baselineAdjustment` property

### Drawing a Shadow

- `shadowColor` property
- `shadowOffset` property
- `shadowOffsetInPoints` property
- `shadowOffsetType` property
- `shadowBlurRadius` property

### Drawing an Outline

- `outlineColor` property
- `outlineWidth` property

### Creating a CCLabelTTF Object

- `+ labelWithString:fontName:fontSize:`
- `+ labelWithString:fontName:fontSize:dimensions:`
- `+ labelWithAttributedString:`
- `+ labelWithAttributedString:dimensions:`

### Initializing a CCLabelTTF Object

- `– initWithString:fontName:fontSize:`
- `– initWithString:fontName:fontSize:dimensions:`
- `– initWithAttributedString:`
- `– initWithAttributedString:dimensions:`
- `– setHTML:`

### TTF Management

- `+ registerCustomTTF:`

## Properties

### adjustsFontSizeToFit

If true, the label will be scaled down to fit into the size provided by the dimensions property. Only has an effect if dimensions are set.

`@property (nonatomic, assign) BOOL adjustsFontSizeToFit`

#### Declared In

`CCLabelTTF.h`

### attributedString

The label attributed text.

`@property (nonatomic, copy) NSAttributedString *attributedString`

#### Declared In

`CCLabelTTF.h`

### baselineAdjustment

Adjusts the fonts baseline, the value is set in points.

`@property (nonatomic, assign) CGFloat baselineAdjustment`

#### Declared In

`CCLabelTTF.h`

### dimensions

Dimensions of the label in Points.

`@property (nonatomic, assign) CGSize dimensions`

#### Declared In

`CCLabelTTF.h`

### dimensionsType

Dimension type of the label.

`@property (nonatomic, assign) CCSizeType dimensionsType`

#### Declared In

`CCLabelTTF.h`

### fontColor

The color of the text (If not using shadow or outline).

`@property (nonatomic, strong) CCColor *fontColor`

#### Declared In

`CCLabelTTF.h`

### fontName

The platform font to use for the text.

`@property (nonatomic, strong) NSString *fontName`

#### Declared In

`CCLabelTTF.h`

### fontSize

The font size of the text.

`@property (nonatomic, assign) CGFloat fontSize`

#### Declared In

`CCLabelTTF.h`

### horizontalAlignment

The horizontal alignment technique of the text.

`@property (nonatomic, assign) CCTextAlignment horizontalAlignment`

#### Declared In

`CCLabelTTF.h`

### minimumFontSize

Used together with adjustsFontSizeToFit. Fonts will not be scaled down below this size (the label will instead be clipped).

`@property (nonatomic, assign) CGFloat minimumFontSize`

#### Declared In

`CCLabelTTF.h`

### outlineColor

The color of the text’s outline.

`@property (nonatomic, strong) CCColor *outlineColor`

#### Declared In

`CCLabelTTF.h`

### outlineWidth

The width of the text’s outline.

`@property (nonatomic, assign) CGFloat outlineWidth`

#### Declared In

`CCLabelTTF.h`

### shadowBlurRadius

The blur radius of the shadow.

`@property (nonatomic, assign) CGFloat shadowBlurRadius`

#### Declared In

`CCLabelTTF.h`

### shadowColor

The color of the text shadow. If the color is transparent, no shadow will be used.

`@property (nonatomic, strong) CCColor *shadowColor`

#### Declared In

`CCLabelTTF.h`

### shadowOffset

The offset of the shadow.

`@property (nonatomic, assign) CGPoint shadowOffset`

#### Declared In

`CCLabelTTF.h`

### shadowOffsetInPoints

The offset of the shadow in points

`@property (nonatomic, readonly) CGPoint shadowOffsetInPoints`

#### Declared In

`CCLabelTTF.h`

### shadowOffsetType

The position type to be used for the shadow offset.

`@property (nonatomic, assign) CCPositionType shadowOffsetType`

#### Declared In

`CCLabelTTF.h`

### string

The label text.

`@property (nonatomic, copy) NSString *string`

#### Declared In

`CCLabelTTF.h`

### verticalAlignment

The vertical alignment technique of the text.

`@property (nonatomic, assign) CCVerticalTextAlignment verticalAlignment`

#### Declared In

`CCLabelTTF.h`

## Class Methods

### labelWithAttributedString:

Creates and returns a label object using the specified attributed text.

`+ (id)labelWithAttributedString:(NSAttributedString *)attrString`

#### Parameters

attrString

  Label Attributed text.

#### Return Value

The CCLabelTTF Object.

#### Availability

Available in iOS 6.0+ and OS X.

#### Declared In

`CCLabelTTF.h`

### labelWithAttributedString:dimensions:

Creates and returns a label object using the specified attributed text and dimensions.

`+ (id)labelWithAttributedString:(NSAttributedString *)attrString dimensions:(CGSize)dimensions`

#### Parameters

attrString

  Label Attributed text.

dimensions

  Label dimensions.

#### Return Value

The CCLabelTTF Object.

#### Availability

Available in iOS 6.0+ and OS X.

#### Declared In

`CCLabelTTF.h`

### labelWithString:fontName:fontSize:

Creates and returns a label object using the specified text, font name and font size.

`+ (id)labelWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size`

#### Parameters

string

  Label text.

name

  Label font name.

size

  Label font size (in points).

#### Return Value

The CCLabelTTF Object.

#### Declared In

`CCLabelTTF.h`

### labelWithString:fontName:fontSize:dimensions:

Creates and returns a label object using the specified text, font name, font size and dimensions.

`+ (id)labelWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size dimensions:(CGSize)dimensions`

#### Parameters

string

  Label text.

name

  Label font name.

size

  Label font size (in points).

dimensions

  Label dimensions.

#### Return Value

The CCLabelTTF Object.

#### Declared In

`CCLabelTTF.h`

### registerCustomTTF:

Register a TTF font resource.

`+ (void)registerCustomTTF:(NSString *)fontFile`

#### Parameters

fontFile

  Font file path.

#### Declared In

`CCLabelTTF.h`

## Instance Methods

### initWithAttributedString:

Initializes and returns a label object using the specified attributed text.

`- (id)initWithAttributedString:(NSAttributedString *)attrString`

#### Parameters

attrString

  Label Attributed text.

#### Return Value

An initialized CCLabelTTF Object.

#### Availability

Available in iOS 6.0+ and OS X.

#### Declared In

`CCLabelTTF.h`

### initWithAttributedString:dimensions:

Initializes and returns a label object using the specified attributed text and dimensions.

`- (id)initWithAttributedString:(NSAttributedString *)attrString dimensions:(CGSize)dimensions`

#### Parameters

attrString

  Label Attributed text.

dimensions

  Label dimensions.

#### Return Value

An initialized CCLabelTTF Object.

#### Availability

Available in iOS 6.0+ and OS X.

#### Declared In

`CCLabelTTF.h`

### initWithString:fontName:fontSize:

Initializes and returns a label object using the specified text, font name and font size.

`- (id)initWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size`

#### Parameters

string

  Label text.

name

  Label font name.

size

  Label font size (in points).

#### Return Value

An initialized CCLabelTTF Object.

#### Declared In

`CCLabelTTF.h`

### initWithString:fontName:fontSize:dimensions:

Initializes and returns a label object using the specified text, font name, font size and dimensions.

`- (id)initWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size dimensions:(CGSize)dimensions`

#### Parameters

string

  Label text.

name

  Label font name.

size

  Label font size (in points).

dimensions

  Label dimensions.

#### Return Value

An initialized CCLabelTTF Object.

#### Declared In

`CCLabelTTF.h`

### setHTML:

(OS X) HTML Label

`- (void)setHTML:(NSString *)html`

#### Parameters

html

  HTML Description.

#### Declared In

`CCLabelTTF.h`