Menu
Coddy logo textTech

Fonts

Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 5 of 50.

The .font modifier sets the size and style of text. SwiftUI has named text styles that match the system's type sizes:

Text("Welcome")
    .font(.largeTitle)

From largest to smallest the common styles are .largeTitle, .title, .headline, .body (the default), .subheadline and .caption.

Make text bold with .bold(), or pick a weight with .fontWeight. A fixed size comes from .system(size:):

Text("Score")
    .font(.title)
    .bold()

Text("42")
    .font(.system(size: 60))
    .fontWeight(.heavy)
challenge icon

Challenge

Beginner

Style the cafe's name: give the text the .largeTitle font and make it bold.

Try it yourself

import SwiftUI

@main
struct CoddyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to SwiftUI

Practice on your own: Swift playground