Swift and SwiftUI tutorials for Swift Developers

How to add custom fonts to Xcode in Swift

The San Francisco font was introduced in November 2014 and has been used as the default font in iOS apps. What happens if you find an open-source font on Google Fonts (https://fonts.google.com) and want to use it in your Swift app? How?


Xcode has made it much easier for developers to use custom fonts. You just need to add the custom font files to your Xcode project. For example, if you prefer to use the Roboto font in your app, you can go to https://fonts.google.com/specimen/Roboto. Click Get Font to download the files.

Once you have downloaded the font you like, let’s add the fonts to Xcode. In our case, in this example, we’ll select two files: Roboto-Bold.ttf and Roboto-ExtraBold.ttf and add them to our Xcode project by dragging them.

Once you add the files to Xcode, the dialog box shown in the following image will appear:

Make sure you select the Copy files to destination option in the dialog box that appears in Xcode once you drag the fonts into your project.

When you press Finish the font files will appear in the project navigator. To ensure the app can use them, hold down the Command key to select them all.

Finally, we need to add a new key called Fonts provided by application to the Info.plist file. This file is a configuration file for your Xcode project. To use custom font files, you must register them in the settings.

By default, Xcode doesn’t display the Info.plist file in the project navigator. You must right-click your project and select the destination. Then, select the Info tab to view the custom properties of the iOS destination.

Next, hover over the Bundle name and you’ll see a + button. Click it to add a new key. Set the key name to Fonts provided by application and fill in the value of element 0 as Roboto-Bold.ttf. Then, click the + button to add another element. Set the value of element 1 to Roboto-ExtraBold.ttf.

This is the process for installing custom fonts in Xcode.

To use the font in Xcode, simply write the following code:

.font(.custom("Roboto-Bold", size: 25))

In our example, using the Roboto font, the result for our iOS app would be the following:

If you have any questions about this article, please contact me and I’ll be happy to help 🙂 You can contact me on my X profile or on my Instagram profile.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

How to hide navigation arrow or disclosure indicator in SwiftUI

Next Article

How to change the navigation bar title font color in SwiftUI

Related Posts