Advertisements
Everything about iOS app development
How To Add Custom Fonts To Your IOS App In Swift

How to add custom font into your iOS app

Post Series: Create an iOS app

iOS apps usually come with the default font that can be edited inside Xcode and many developers use them cause it’s easy and doesn’t take any extra time and effort.

However using a custom font can make your app stand out, I truly believe that font is KING. For the untrained eye it doesn’t matter  font – font, all they care about is readability, but having a custom font can change your app’s look. Learn more about fonts here: https://developer.apple.com/fonts/

Adding a custom font

Adding your own font is easy in iOS, you need to 4 things.

 

1. First you need to download it and add it to your project. Simply add it to your project.

Adding custom font to Xcode

2. Next you need to add these to your Info.plist file so iOS can recognize and you can use it in your app.

Adding font to your info.plist swift

3. What I like to do before connecting my labels and ui elements in my app is printing out the UIFont family names and the fonts that are available for that family. This way I can be sure that I’m using the right name, as sometimes the font’s file name is different to its real name, if that makes sense.

Use this snippet to print out all the available names. Just put it into AppDelegate, or a viewDidLoad method.

Than, look for your font you added, if you can’t find it go back to Step 1.

If your font is there, use this snippet to find the names of your fonts:

In my case I added Montserrat fonts, so my line looked like this:

print(UIFont.fontNames(forFamilyName: “Montserrat”)).

Once you’re done with all that, you can use your font inside your app, it will be available in Interface Builder and can be called with a simple UIFont method as well.

But what I like to do to make my life easier and be a better developer, is to create an object that could handle these fonts.

So as you can see, I created a custom object that has a static function inside it that would return my font, in the size and weight I want.

Than you just use it simply like this:

Check out my Youtube tutorial if you like to see it in action.

Recent posts

Advertisements
%d bloggers like this: