Timering

Purp

Swift Custom Font import & UIFont Family Names List - IOS, Swift 2.2

This is a Swift 2.2 version of previous ObjC tutorial. Sometimes it's very useful to check, which UIFonts are already available, and which should be imported. In this little tutorial, I will show, how can you import your own custom Font, and how can you check the available UIFonts and Families in your Xcode Project. IOS 9.3 Xcode 7.3 Swift 2.2

Steps

  1. Check the available UIFont Families - Log their names
  2. Import your own Font into your Swift Project
  3. Check the available Font Families and their Font Names again.

Video

1. Check the available UIFont Families - Log their names

Create a SingleView Xcode Project. In your ViewController.swift file put this code to print out your all available UIFonts:

Now run your project and check the logs. My result:

Swift UIFont Family Name List - Custom UIFont Import 1_2

2. Import your own Font into your Swift Project

If you have one, that's ok, if you need one, download here a new Font: www.google.com/fonts

Find a Font, which isn't in your Log list! :) I will import here Lato.

UIFont Custom Import Xcode IOS 9.3

2.1 Download and Add to your Xcode Project 

Download it with click on the right small arrow, and choose .zip. After that, drag and drop in Xcode.

Swift UIFont Family Name List - Custom UIFont Import 1_3

2.2 Now you need to add your new File names at Info.plist file. 

Click on your Info.plist file, and at "Information Property List" click the plus button, and search (start to type) for "Fonts provided by application". 

Add new File names as new Items. (Very important to use the exact name of the Font file!)

Swift UIFont Family Name List - Custom UIFont Import 1_4

2.3. Check it!

And Check your Target at Build Phases under the "Copy Bundle Resources", that your all imported files are there! 

Swift UIFont Family Name List - Custom UIFont Import 1_5 bundle resources

3. Check the available Font Families and their Fonts again.

If everything works fine, you can check your available UIFonts again. Run your App. And in Log with cmd+f search for your new Font Name. (First of all, trash your log ;) 

Swift UIFont Family Name List - Custom UIFont Import 1_6 list custom font

Now you can see your new UIFont names. You must to use these names in your log, if you use it with this form for instance: "string.font = UIFont(name: "Lato-Black", size: 12)" Sometimes what you can see in log is different from your exact File name. Therefore you need to check it always after your import.

And of course, if you don't add your Font name to your Info.plist file, that will be mot available in your App. At me, I added just 4 type of this Font Family, and if I want to use "Lato-Italic", that will be not work, because I didn't add it to the Info.plist file. 

Download:

Download the Xcode template from Github.

Share & Follow

If you would like to be notified of my new solutions, please subscribe to my Newsletter or my youtube channel and/ or follow me on Facebook or Twitter! Check Footer section for these opportunities!