How to use custom fonts in Swift iOS app using SwiftUI

There are several steps you need to perform in order to add a custom font to your Swift iOS app. The steps outlined below apply to both SwiftUI and UIKit apps. This tutorial assumes that you already have your font files handy on your Mac (if not, don’t worry, at the end of the tutorial I’ll include steps to getting font files included on your macOS). This tutorial will also show how to find custom fonts already available on iOS.

Import font files to Xcode project

With your Xcode project open, select File -> Add Files to “Your Project” from Xcode’s menu bar.

Xcode: File -> Add Files to “Your Project”
Xcode: File -> Add Files to “Your Project”

Then, locate your font file(s) on disk. Make sure that “Copy items if needed” is selected and “Add to targets” has your project name in the list and is selected as well. This is a very important step. Click Add.

Import fonts file to Xcode
Import fonts file to Xcode

Set Target Membership for the font files

Confirm that your font file(s) got properly added to your project and their Target Membership is properly selected. Click on each font file added and confirm the following from the screenshot below:

Set Target Membership for the font files
Set Target Membership for the font files

Update Info.plist file

Click on Info.plist in your Xcode’s project and add new “Fonts provided by application” key by clicking on the little plus icon in the first row.

Update Info.plist file with Fonts provided by application key
Info.plist

Make sure that the new “Fonts provided by application” key is an Array type and add new items to the array, one for each font file you imported. Names of the items should match imported font file names.

Fonts provided by application in Info.plist contain font file names
Fonts provided by application in Info.plist contain font file names

Use new font in code

At this point you’re ready to use the newly imported font in your SwiftUI project:

Text("Simple Swift Guide").font(Font.custom("Chalkboard", size: 33))
Using custom Chalkboard font in SwiftUI
Using custom Chalkboard font in SwiftUI

Check out our previous tutorial if you’d like to learn more about using Fonts and customizing them in SwiftUI.

In order to use the new font in a UIKit project, set the label’s font to custom UIFont like that:

@IBOutlet weak var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    label.font = UIFont(name: "Chalkboard", size: 33)
}

Locating custom fonts available on iOS

You can find out what other fonts are already available on iOS to use in your app by running the following code which prints out all font names:

for fontFamily in UIFont.familyNames {
    for fontName in UIFont.fontNames(forFamilyName: fontFamily) {
        print("\(fontName)")
    }
}

This code can, for example, be run in SceneDelegate.swift file inside scene(_ scene: UIScene, willConnectTo…) method.

Custom fonts available on iOS
Custom fonts available on iOS

Then, just pick one name (e.g., Copperplate) and use it:

Text("Simple Swift Guide").font(.custom("Copperplate", size: 33))

Troubleshooting

If for some reason you’re still not able to use your font, make sure the font files are included in Copy Bundle Resources under Build Phases of your Xcode project settings:

Xcode's Build Phases - Copy Bundle Resources
Xcode’s Build Phases – Copy Bundle Resources

Getting custom fonts from macOS Catalina

Open Font Book application on your Mac running macOS Catalina. Locate the font you’d like to import to your iOS app, right click on it and select “Show in Finder”, then use that file to complete this tutorial starting from the first step.

Font Book application on macOS
Font Book application on macOS

Related tutorials:

Apple’s official Font documentation has more information on the topic as well.