Black Friday 2024 deal: 30% off our Swift and SwiftUI books! Learn more ...Black Friday 2024 deal:30% off our Swift and SwiftUI books >>

Font modifiers in SwiftUI

We are all familiar with view modifiers in SwiftUI, such as font(), background(), frame(), etc. We use them all the time to style and customize views in our apps. They are methods defined on the View type that return a different version of the original view. I previously wrote about text modifiers, which are methods applied directly to Text, returning a modified Text, that can be used inside text interpolation. In this post I'd like to explore font modifiers, which work similarly to view and text modifiers but are applied to the Font type, returning a modified font.

Here is an example of font modifiers in action. We apply bold(), monospaced() and smallCaps() to the largeTitle font to customize the way it looks.

Text("Hello, world!")
    .font(
        .largeTitle
            .bold()
            .monospaced()
            .smallCaps()
    )
iPhone screen displaying text in bold, monospaced and small caps iPhone screen displaying text in bold, monospaced and small caps
Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Black Friday 2024 offer: 30% off!$35$25

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms
Black Friday 2024 offer: 30% off!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35$25

We can view the full list of font modifiers in SwiftUI Font documentation in the "Styling a font" section. We can see that they are not exactly the same as modifiers available on the Text type or methods for styling text on the View type.

For example, there is a font modifier for customizing leading, which lets us adjust the line spacing of a font and takes a Font.Leading enum as an argument. This modifier can't be applied to a Text or any other view, only to a Font.

VStack(spacing: 20) {
    Text(exampleText)
        .font(
            .largeTitle
                .leading(.tight)
        )
    Text(exampleText)
        .font(
            .largeTitle
                .leading(.loose)
        )
}
iPhone screen displaying text with tight leading and loose leading iPhone screen displaying text with tight leading and loose leading

Font modifiers are a great way to manage typography in SwiftUI, letting us style text directly at the font level. Using these modifiers thoughtfully can help us create a polished look that improves our app’s user experience.


If you have older iOS apps and want to enhance them with modern SwiftUI features, check out my book Integrating SwiftUI into UIKit Apps. It provides detailed guidance on gradually adopting SwiftUI in your UIKit projects. Additionally, if you're eager to enhance your Swift programming skills, my latest book Swift Gems offers over a hundred advanced tips and techniques, including optimizing collections, handling strings, mastering asynchronous programming, and debugging, to take your Swift code to the next level.

I’m currently running a Black Friday 2024 promotion with 30% off my books, plus additional savings when purchased as a bundle. Visit the books page to learn more.

Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover

Black Friday 2024 offer: 30% off!$45$32

A detailed guide on gradually adopting SwiftUI in UIKit projects

Updated for iOS 18 and Xcode 16!

Integrating SwiftUI into UIKit Appsby Natalia Panferova

  • Upgrade your apps with new features like Swift Charts and Widgets
  • Support older iOS versions with effective backward-compatible strategies
  • Seamlessly bridge state and data between UIKit and SwiftUI using the latest APIs
Black Friday 2024 offer: 30% off!

A detailed guide on gradually adopting SwiftUI in UIKit projects

Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover

Integrating SwiftUI
into UIKit Apps

by Natalia Panferova

Updated for iOS 18 and Xcode 16!

$45$32