How to add a custom font to an XCode Project

Oscar de la Hera Gomez
A flower that represents Swift next to a flower that represents XCode. Beneath it sits the text that states 'Add a Custom Font'.

A step by step tutorial on adding a font to an iOS, MacOS, TVOS or WatchOS project in XCode and Swift.

The following tutorial builds on our Open Source Swift project, which can be downloaded using the link below, and which walks you through how to add a font to your project in Xcode. Please note that this process is the same for iOS, MacOS, TVOS and WatchOS.

Please note that this tutorial makes use and expands on Apple's reference for adding fonts to an XCode project.

Tutorial

We recommend downloading our Open Source project, checking out the main branch and carrying out the steps outlined below. All relevant changes can be found on the tutorial/add-a-font branch.

git clone git@github.com:delasign/swift-starter-project.git

Step One: Add your font to XCode

A screenshot showing the custom font that we added to Xcode. Carry the steps below to achieve this result.

The following step details how to add a font to your project. Please note that we will be using Montserrat, which we gathered using Google Fonts.

A | Select Add the File to your project in Xcode

A screenshot giving you guidance as to how you can add a files to an XCode project.

Under the Files folder, within the Fonts folder, right click and select Add Files to "Starter Project"...

Please note that "Starter Project" is the name of our Open Source starter project and will be different if this is in your own project.

B | Add your Font to Xcode

A screenshot of the window that appears in Xcode when you add a file. It highlights the file name, the destination checkbox that must be checked off and the target checkbox that must be checked off.

In the Finder window that appears, navigate to the location of the Font. Once you have selected it, make sure that:

  • The destination has Copy items if needed checked off.
  • The Add to Targets section has a checkbox next to your project.

Once you're ready, click Add.

Step Two: Copy the name of the font

A screenshot showing you where you can find and copy the name of the font within an XCode Project. Details are provided in the text below. To open the inspector, select the button found on the top right of Xcode. Select the first menu option that appears, which is titled Identity and Type, and in the first Input - copy the text.

In Inspector, on the right hand side of XCode, under Identity and Type - Copy the name of the font.

Please note that in order to make the Inspector appear you must select the button on the top right that is outlined in red.

Step Three: Add font to the Info.plist

A screenshot demonstrating how we added the font to the info.plist. Follow the text below to replicate it.

Select the Info.plist and add a new row. In the row that appears, enter Fonts provided with applications - which will create an array with an empty item. In this empty item, paste the name of the font that you copied in Step Two.

Please note that at this step, Xcode has incorporated the font into the app and it can now be used. The next step informs you on how you can use it.

Step Four: Add the font to the Fonts.swift

A screenshot of our updated Fonts.swift file which includes the custom font that we added in the tutorial.

The following step details how to determine what string the system uses for the font that you added in this tutorial, and to make it available via the fonts on our Styleguide, which are declared in Fonts.swift.

A | Print all the system fonts

A screenshot showing how we added the printSystemFonts function call below the self.setupUI function call within the ViewController.swift, ViewDidLoad function.

Navigate to ViewController.swift and in ViewDidLoad, call the printSystemFonts utility.

For your convenience, we have provided the code to the utility below.

B | Determine the system name for the font

A screenshot of how we used XCode's Debug area, logs and filter to determine the name of the font.

Run your app, and filter the logs for the your font name. Once you find it, copy the name - in the case of this tutorial its Montserrat-Regular.

C | Add the font to Fonts.swift

A screenshot of our updated Fonts.swift file which includes the custom font that we added in the tutorial.

In Fonts.swift add your font to the Fonts struct as demonstrated in the image above.

Seeking to apply the font to a label ?

If you wish to learn about our Styleguide and how we use it to create standard or attributed labels please consult our tutorials below.

Any Questions ?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.

delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details