iOS Developer Library — Pre-Release

Developer

SpriteKit Framework Reference SKLabelNode Class Reference

Options
Deployment Target:

On This Page
Language:

SKLabelNode

An SKLabelNode is a node that draws a string. More...

Inheritance


Conforms To


Import Statement


Swift

import SpriteKit

Objective-C

@import SpriteKit;

Availability


Available in iOS 7.0 and later.
  • Initializes a new label object.

    Declaration

    Swift

    init(fontNamed fontName: String!)

    Objective-C

    - (instancetype)initWithFontNamed:(NSString *)fontName

    Parameters

    fontName

    The name of the font used by the label.

    Return Value

    An initialized label object.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates a new label object.

    Declaration

    Objective-C

    + (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.

  • Creates a new label object with some initial text.

    Declaration

    Swift

    convenience init(text text: String)

    Objective-C

    + (instancetype)labelNodeWithText:(NSString *)text

    Parameters

    text

    The text to use to initialize the label node.

    Return Value

    A new initialized label object.

    Discussion

    The label node’s font is set to Helvetica Neue Ultralight, 32 point.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • text text Property

    The string that the label node displays.

    Declaration

    Swift

    var text: String

    Objective-C

    @property(nonatomic, copy) NSString *text

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • fontColor fontColor Property

    The color of the label.

    Declaration

    Swift

    var fontColor: UIColor

    Objective-C

    @property(nonatomic, retain) UIColor *fontColor

    Discussion

    The default color is white.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • fontName fontName Property

    The font used for the text in the label.

    Declaration

    Swift

    var fontName: String!

    Objective-C

    @property(nonatomic, copy) NSString *fontName

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • fontSize fontSize Property

    The size of the font used in the label.

    Declaration

    Swift

    var fontSize: CGFloat

    Objective-C

    @property(nonatomic) CGFloat fontSize

    Discussion

    The default font size is 32 points.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • color color Property

    The label’s blend color.

    Declaration

    Swift

    var color: UIColor?

    Objective-C

    @property(nonatomic, retain) UIColor *color

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    colorBlendFactor

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

    Declaration

    Swift

    var colorBlendFactor: CGFloat

    Objective-C

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

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    color

  • blendMode blendMode Property

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

    Declaration

    Swift

    var blendMode: SKBlendMode

    Objective-C

    @property(nonatomic) SKBlendMode blendMode

    Discussion

    The default value is SKBlendModeAlpha.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Options for aligning text vertically.

    Declaration

    Swift

    enum SKLabelVerticalAlignmentMode : Int { case Baseline case Center case Top case Bottom }

    Objective-C

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

    Constants

    • Baseline

      SKLabelVerticalAlignmentModeBaseline

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

      Available in iOS 7.0 and later.

    • Center

      SKLabelVerticalAlignmentModeCenter

      Centers the text vertically on the node’s origin.

      Available in iOS 7.0 and later.

    • Top

      SKLabelVerticalAlignmentModeTop

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

      Available in iOS 7.0 and later.

    • Bottom

      SKLabelVerticalAlignmentModeBottom

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

      Available in iOS 7.0 and later.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Options for aligning text horizontally.

    Declaration

    Swift

    enum SKLabelHorizontalAlignmentMode : Int { case Center case Left case Right }

    Objective-C

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

    Constants

    • Center

      SKLabelHorizontalAlignmentModeCenter

      Centers the text horizontally on the node’s origin.

      Available in iOS 7.0 and later.

    • Left

      SKLabelHorizontalAlignmentModeLeft

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

      Available in iOS 7.0 and later.

    • Right

      SKLabelHorizontalAlignmentModeRight

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

      Available in iOS 7.0 and later.

    Import Statement

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.