-1

I want to use custom fonts(external fonts) to my project programmatically.

  1. I added fonts to my project folder.
  2. Recorded imported fonts to the info.plist Recording info.plist
  3. Copy that font file to the BuildPhases->Copy Bundle Resources Copy Bundle Resources
  4. The fonts appear in Attributes Inspector Attributes Inspector

But when I implement this code to get custom font names, a lot of fonts appear but my custom fonts do not appear on the console.

 for the family: String in UIFont.familyNames
        {
            print(family)
            for names: String in UIFont.fontNames(forFamilyName: family)
            {
                print("== \(names)")
            }
        }

So as mentioned below, When I implemented attributed string in my project programmatically,

let att1 = [NSAttributedString.Key.font : UIFont(name: "Sofia Pro", size: 18.0)]

It crashed and say unrecognized selector sent to instance

Did I skip any step?

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

When you add font in your project the you must select Add to target as show in given image:-

enter image description here

Then you can select your font from your Xcode.

enter image description here

There is no need to add Fonts in info.plist and any other place.

Bijender Singh Shekhawat
  • 3,934
  • 2
  • 30
  • 36
-2

Must recorded in plist

Now it is working. But if you want to use your font programmatically, You have to add your fonts into info.plist. As seen in the screenshot, only info.plist fonts appear on the console and I can use them in programmatic way.

let att1 = [NSAttributedString.Key.font : UIFont(name: "SofiaPro-LightItalic", size: 18.0)]

I can not use others in a programmatic way. When used, it crashed.