Using custom fonts in SwiftUI
iOS comes with many preinstalled fonts that can be safely used in SwiftUI. However, the design of the app sometimes needs some custom fonts because they might be a part of the brand of the app maker.
In this recipe, we’ll see how to import a couple of custom fonts for building a menu page for an Italian restaurant.
Getting ready
- Create a SwiftUI app called
RestaurantMenu
. - Get the Sacramento, Oleo Script Regular, and Oleo Script Bold custom fonts, which you can find in the repository at https://github.com/PacktPublishing/SwiftUI-Cookbook-3rd-Edition/tree/main/Resources/Chapter17/recipe2.
- Drag the font files to the Xcode project navigator pane to add the fonts as resources to the project, as shown in the following figure:
Figure 17.8: Custom fonts added to the project
- Make sure the Copy items if needed and RestaurantMenu options are checked:
Figure 17.9: Adding custom font files...