18

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

How do I go about this?

Christian
  • 22,585
  • 9
  • 80
  • 106
LukeTerzich
  • 555
  • 1
  • 4
  • 17

4 Answers4

29

For SKLabelNode's you need to use:

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

or

var labelNode = SKLabelNode()
labelNode.fontName = "AvenirNext-Bold"
PoisonedApps
  • 716
  • 8
  • 21
4

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/

Christian
  • 22,585
  • 9
  • 80
  • 106
  • For some reason the .Font isn't recognised though - SKLabelNode doesn't have a member named Font – LukeTerzich Jan 27 '15 at 14:22
  • you have to write the .font with a lowercase 'f'. – Christian Jan 27 '15 at 14:23
  • tried both and still get not a member (even with .font) – LukeTerzich Jan 27 '15 at 14:25
  • Ah i see. you are using an SKLabelnode. I thought that you were using an UILAbel. I've updated my answer. – Christian Jan 27 '15 at 14:29
  • That did it! Perfect! Thanks Guys - What is the default font of the LabelNode? I don't want to choose a new font and i don't know the name of the default one – LukeTerzich Jan 27 '15 at 14:31
  • 1
    You can get the Fontname by simply print it out: println(skLabel.fontName). If my answer solved your problem please click on the tick on the left side of my answer so that other people can find it easier. – Christian Jan 27 '15 at 14:33
3

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
        }
    }
}
OwlOCR
  • 1,127
  • 11
  • 22
-3

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)