How to add Custom Fonts in your iOS app using Swift
- February 02, 2020
- John Codeos
Today, I’m going to show you how to add custom fonts in your iOS app quickly.
In this example, we are going to add 2 fonts, Mallent (MallentRegular.ttf) and Great Wishes (Best.otf), in our iOS project.
Adding Custom Fonts to the project
First, create a folder with a name Fonts in your project. Go to your project and right-click > New Group
Drag and Drop your font files in the new folder and choose the checkboxes for Copy items if needed and Add to targets.
Then press Finish.
After adding the fonts, the Fonts folder will look like this:
Now, go to Info.plist and hover your mouse over the Information Property List and press the + button and type Fonts provided by application and press Enter
Press the arrow next to Fonts provided by application and add the font file names.
Using Custom Fonts in the app
Go to the UILabel you want to use the custom font and add it:
It didn’t work! What I’m doing wrong?
Sometimes the font file name differs from the font name. In this example, we have a font file name Best.otf, but the name of the font is not Best.
If we try to add the font like that:
We need to use the name of the font, not the name of the font file.
To find the name of the font, go to your font file and Right-Click > Get Info
So the font name is GreatWishes.
So the right way is:
You can find the final project here
If you have any questions feel free to DM me on Twitter @johncodeos or leave a comment below!