15
votes

As the title states - I would like to make my SKLabelNodebold programmatically.

How do I go about this?

4

4 Answers

27
votes

For SKLabelNode's you need to use:

var labelNode = SKLabelNode()
labelNode = SKLabelNode(fontNamed: "AvenirNext-Bold")

or

var labelNode = SKLabelNode()
labelNode.fontName = "AvenirNext-Bold"
4
votes

You can't set the SKLabelNode itself to bold. You have to use a Bold Font.

But if you want to use a custom font, you have to use one which is available in bold:

skLabel.fontName = "YourFontName-Bold"
skLabel.fontSize = 14

To get all fonts which are available on iOS check this site: http://iosfonts.com/

3
votes

Here's a little extension for SKLabelNode. Allows you to toggle between bold and non-bold. Return value tells if it is currently set to bold.

extension SKLabelNode
{
    func toggleBold() -> Bool
    {
        if var range = self.fontName.rangeOfString("-Bold")
        {
            self.fontName = self.fontName.substringToIndex(range.startIndex)
            return false
        }
        else
        {
            self.fontName = self.fontName + "-Bold"
            return true
        }
    }
}
-3
votes

Use font property of UILabel

label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)

or use default system font to bold text

lable.font = UIFont.boldSystemFontOfSize(16.0)