SKLabelNode Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/SpriteKit.framework
Availability
Available in iOS 7.0 and later.
Companion guide
Declared in
SKLabelNode.h

Overview

An SKLabelNode is a node that draws a string.

To use a label node, create a new label node by calling the labelNodeWithFontNamed: class method. Then configure the other label properties, especially the text property.

The size of a label node is determined implicitly by the label node’s fontName, fontSize, and text properties. By default, the text label is centered horizontally on the label node’s origin, with the font’s baseline passing through the origin. The verticalAlignmentMode and horizontalAlignmentMode properties can be used to adjust the label’s position relative to the origin.

Tasks

Creating a New Label Node

Configuring the Label Message

Configuring the Label Font

Configuring the Label’s Position

Performing Color Blending

Blending the Label Into the Framebuffer

Properties

blendMode

The blend mode used to draw the label into the parent’s framebuffer.

@property(nonatomic) SKBlendMode blendMode
Discussion

The default value is SKBlendModeAlpha.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

color

The label’s blend color.

@property(retain, nonatomic) SKColor *color
Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

colorBlendFactor

A floating-point value that describes how the color is blended with the font color.

@property(nonatomic) CGFloat colorBlendFactor
Discussion

The value must be a number between 0.0 and 1.0, inclusive. The default value (0.0) indicates that color property is ignored and that the label’s font color should be used unmodified. For values greater than 0.0, the font color is blended first with the blend color.

Availability
  • Available in iOS 7.0 and later.
See Also
Declared In
SKLabelNode.h

fontColor

The color of the label.

@property(retain, nonatomic) SKColor *fontColor
Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

fontName

The font used for the text in the label.

@property(copy, nonatomic) NSString *fontName
Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

fontSize

The size of the font used in the label.

@property(nonatomic) CGFloat fontSize
Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

horizontalAlignmentMode

The horizontal position of the text relative to the node’s position.

@property(nonatomic) SKLabelHorizontalAlignmentMode horizontalAlignmentMode
Discussion

The possible values for this property are listed in “Text Horizontal Alignment Modes”. The default value of this property is SKLabelHorizontalAlignmentModeCenter.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

text

The string that the label node displays.

@property(copy, nonatomic) NSString *text
Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

verticalAlignmentMode

The vertical position of the text relative to the node’s position.

@property(nonatomic) SKLabelVerticalAlignmentMode verticalAlignmentMode
Discussion

The possible values for this property are listed in “Text Vertical Alignment Modes”. The default value of this property is SKLabelVerticalAlignmentModeBaseline.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

Class Methods

labelNodeWithFontNamed:

Creates a new label object.

+ (instancetype)labelNodeWithFontNamed:(NSString *)fontName
Parameters
fontName

The name of the font used by the label.

Return Value

A new initialized label object.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

Instance Methods

initWithFontNamed:

Initializes a new label object.

- (instancetype)initWithFontNamed:(NSString *)fontName
Parameters
fontName

The name of the font used by the label.

Return Value

An initialized label object.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKLabelNode.h

Constants

Text Vertical Alignment Modes

Options for aligning text vertically.

typedef NS_ENUM(NSInteger,
   SKLabelVerticalAlignmentMode) {
   SKLabelVerticalAlignmentModeBaseline    = 0,
   SKLabelVerticalAlignmentModeCenter      = 1,
   SKLabelVerticalAlignmentModeTop         = 2,
   SKLabelVerticalAlignmentModeBottom      = 3,
};
Constants
SKLabelVerticalAlignmentModeBaseline

Positions the text so that the font’s baseline lies on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

SKLabelVerticalAlignmentModeCenter

Centers the text vertically on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

SKLabelVerticalAlignmentModeTop

Positions the text so that the top of the text is on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

SKLabelVerticalAlignmentModeBottom

Positions the text so that the bottom of the text is on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

Text Horizontal Alignment Modes

Options for aligning text horizontally.

typedef NS_ENUM(NSInteger,
   SKLabelHorizontalAlignmentMode) {
   SKLabelHorizontalAlignmentModeCenter    = 0,
   SKLabelHorizontalAlignmentModeLeft      = 1,
   SKLabelHorizontalAlignmentModeRight     = 2,
};
Constants
SKLabelHorizontalAlignmentModeCenter

Centers the text horizontally on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

SKLabelHorizontalAlignmentModeLeft

Positions the text so that that the left side of the text is on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.

SKLabelHorizontalAlignmentModeRight

Positions the text so that that the right side of the text is on the node’s origin.

Available in iOS 7.0 and later.

Declared in SKLabelNode.h.