0

When assigning a font name by code, I need a different name than shown in any dialog for font selection or filename. How I do get the correct spelling? E.g. for

  SKLabelNode(fontNamed: "GillSans-BoldItalic")   /// preload font

The name shown at Fontbook differs from that used by this example. The are spaces in the title of the font, but in code there aren't. And there is a minus used.

When using the code for displaying all font, I couldn't find it because I have installed so much fonts.

Peter71
  • 2,180
  • 4
  • 20
  • 33
  • Possible duplicate of http://stackoverflow.com/questions/31420758/swift-custom-fonts-xcode-7-0-beta. – Martin R Aug 05 '15 at 08:58
  • Have a look here http://iosfonts.com very helpful resource. – sbarow Aug 05 '15 at 09:52
  • Thanks for hint to the fonts.Looks great. – Peter71 Aug 05 '15 at 10:38
  • Ok, i checked this question. I already included the code. But I have a lot of fonts, so I could find it in the generated list. The hint using FontBook is good, but e,g, the name is "Gill Sans Bold Italic" (shown on top). But the name used by a tutorial is without spaces and with minus between name and style. Is this the normal way? – Peter71 Aug 05 '15 at 10:39

1 Answers1

0

If you don't need a runtime solution in your application you could use this AppleScript. It retrieves the name by scripting Font Book. The result is also copied to the clipboard

set requestedFontName to text returned of (display dialog "Enter 'human readable' font name" default answer "")
try
    tell application "Font Book"
        set fontName to PostScript name of 1st typeface whose name is requestedFontName
    end tell
    display dialog fontName buttons {"OK"} default button 1
    set the clipboard to fontName
on error
    display dialog "no match found"
end try
vadian
  • 274,689
  • 30
  • 353
  • 361