Home > OS >  Custom font not loading in SwiftUI project after moving code to another project?
Custom font not loading in SwiftUI project after moving code to another project?

Time:04-20

I had a SwiftUI project that I essentially messed up pretty bad and had to make a new project and transfer all the files over. It's working as intended except for my custom fonts aren't working and the default font is taking over. Here is what I did:

  1. Copied my fonts folder into my new project
  2. Checked the Target Membership box for my project and made sure that the path to the directory was referring to the new path, not the old path (bc it was before I changed it).
  3. Included the names of both fonts in my plist, exactly how they were in the initial project's plist, in the fonts provided by application array.
  4. Deleted and readded the fonts folder in my project's Build Phases (again, to make sure it was referring to the correct directory).

And yeah, still not working. Any insight as to what I could be overlooking? Because it was working completely as intended before I had to create the new project, and all other elements are working as intended.

CodePudding user response:

Although it looks like you have already done this, just go through the following checklist once:

  1. Fonts (.ttf files) are present inside the project font files location
  2. Entry in info.plist file enter image description here
  3. Entry in "Copy Bundle Resources" under "Build Settings" of your target enter image description here If this is missing, add by clicking on the plus ( ) icon in this section
  4. Make sure you are using the font correctly (check spelling errors?)
var FontRegular : Font = Font.custom("Poppins-Regular", size: 16)
var FontBold    : Font = Font.custom("Poppins-Bold", size: 16)

...

Text("Sample Text")
    .font(FontRegular)
  • Related