skip to Main Content

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.

2

Answers


  1. 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)
    
    Login or Signup to reply.
  2. If you are struggling with this in 2022 and using SwiftUI where there seems to be no info.plist in sight, then in addition to adding the Fonts capability in Target Signing and Capabilities, then dragging the file into your project and don’t forget to check Add to Targets, and finally add your InsertFontFileName.ttf to "Fonts provided by application" which is now in your Info tab on the Target as seen in the image below. Also, call me crazy but before you drag the font in remove any special characters. In addition, don’t be fooled by the auto-generated info.plist, add your new fonts via the image below, it’ll auto-populate to that other plist. Maybe some of my steps are superstitious, but I spent enough time futzing around with fonts that I’m done thinking about it and I’ll just follow my formula… and if that font doesn’t work, it wasn’t meant to be and I’ll move onto the next font!

    After that

    .font(Font.custom("InsertFontFileName", size: 32, relativeTo: .title))
    

    place in xcode where the code is located

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search