Adding custom font to Xcode 13+
Asked Answered
V

3

9

Now that Apple has taken away the Plist, naturally it has changed the way we add custom fonts to our app. Before we just added the file to our bundle and set a property for it and our plist and viola..

Now I am curious.. can it be done without adding a custom plist as shown here or is that the only option?

Veratrine answered 20/6, 2021 at 13:17 Comment(0)
T
19
  1. drag and drop your font-file into the project (make sure you hit copy if needed and check the target box)

drag&drop

  1. choose Project -> Targets -> Info -> Custom iOS Target Properties and klick the small + icon under the "key" property. Start typing "Fonts provided by application"

enter image description here

  1. enter the full font-filename inside this property-list

enter image description here

  1. now you can use the font by its name

  2. (Bonus: if you have trouble to find the font name, you can print all available fonts with [see detail explanation for this at code with chris ]:

 for family: String in UIFont.familyNames
        {
            print(family)
            for names: String in UIFont.fontNames(forFamilyName: family)
            {
                print("== \(names)")
            }
        }
Tautology answered 24/9, 2021 at 8:59 Comment(0)
C
3

You can add font files name same as you add in project directory info.plist

Just go to

Project -> Targets -> Info -> Custom iOS Target Properties

Add your all permission or file here.

enter image description here

Cockahoop answered 20/6, 2021 at 14:28 Comment(1)
I don't think that's what he or she is talking about if you read the forwarding topic.Dix
C
0

Also when using the font in swiftui you need to remove the .ttf

so Silkscreen-Regular.ttf is Silkscreen-Regular

struct ContentView: View {
var body: some View {
//run this init to get a list of all of the fonts you project can see
 init() {
    for familyName in UIFont.familyNames {
        print(familyName)
        for fontName in UIFont.fontNames(forFamilyName: familyName){
            print("--\(fontName)")
        }
    }
   }
  }
Chaise answered 17/10, 2023 at 14:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.