Manngo
Manngo

Reputation: 16281

How do I use Font Awesome as a custom font in SwiftUI?

I have followed a number of tutorials in adding a custom font to my SwiftUI package. I have take the following steps:

I tried the following:

Text(Text("\u{f071} Danger Will Robinson").font(.custom("Font Awesome 5 Free Regular", size: 20))

which is supposed to give me an alert icon, but all I get is a question mark.

Is there a trick to using Font Awesome in this way?

I know there are a few packages available, but I’m trying to learn more about the process itself, and I can’t see that it should be too hard.

Upvotes: 2

Views: 1617

Answers (1)

Manngo
Manngo

Reputation: 16281

OK, I worked it out.

  • For MacOS, the Info.plist key is: Application fonts resource path, not as above.
  • The next trick is to get the font name.

One method is to install the font, and then check FontBook. The PostScript name is the name I need.

The other is to run the following code:

let fontManager = NSFontManager.shared
let fonts = fontManager.availableFonts
for name in fonts {
    print(name)
}

That’s what happens when all the tutorials are for iOS, not MacOS.

Upvotes: 4

Related Questions