Fonts
Anonymous contributor
Published May 18, 2023Updated Oct 5, 2024
Contribute to Docs
Font
is a struct
that creates Font
instances that can be applied to text by passing them to the .font()
view modifier.
Font
instances can be created using standard fonts, which are type properties of Font
. Fonts can also be created and modified using built-in Font
methods such as .system()
, .italic()
, and .bold()
.
Standard Fonts
Below is a list of some of the standard Font
type properties:
.largeTitle
a large, title font style..title
a title font style..title2
a smaller title font style..title3
the smallest title font style..headline
a headline font style..body
the default font style..footnote
a footnote font style..caption
a caption font style.
Modifying and Creating Fonts
Below is a list of some of the Font
methods used to modify and create fonts:
.bold()
applies a bold style..italic()
applies an italic style..weight()
applies the specified weight style..monospaced()
applies a monospaced font style..lowercaseSmallCaps()
converts lowercase characters to small capital characters..system(_ style:, design:, weight:)
applies a specified font style with optional design and/or weight styles..system(size:, weight:, design:)
applies a specified size with optional weight and/or design styles.
It is also possible to create custom fonts using the .custom()
method.
Example
The following example shows a VStack
containing text views with three different fonts applied:
import SwiftUIstruct FontView: View {let titleFont = Font.largeTitle.lowercaseSmallCaps()let footnoteFont = Font.system(.footnote, design: .serif, weight: .bold)var body: some View {VStack {Text("I Love to See the Summer Beaming Forth").font(titleFont)Text("\nI love to see the summer beaming forth \nAnd white wool sack clouds sailing to the north \nI love to see the wild flowers come again \nAnd mare blobs stain with gold the meadow drain\n").monospaced()Text("- John Clare").font(footnoteFont)}.padding()}}
In the above example:
- The first text view has
titleFont
applied.titleFont
is created from the standardFont
type property,.largeTitle
, with the method.lowercaseSmallCaps()
applied to it. - The next text view has the method
.monospaced()
applied, setting the text to use a monospaced font. - The last text view has a created system font
footnoteFont
applied, with a.footnote
style,.serif
design, and.bold
weight.
This will display:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SwiftUI on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours