.fontWeight()
Published Feb 18, 2023Updated Mar 2, 2023
Contribute to Docs
The .fontWeight()
modifier sets the font weight of the text in Text View.
Syntax
Text("your text")
.fontWeight(.weight)
.weight
can be one of the following values:
.ultraLight
.thin
.light
.regular
.medium
.semibold
.bold
.heavy
.black
Example
In the following example, the font weight is set using the .regular
and .bold
expressions.
import SwiftUIstruct SomeView: View {var body: some View {VStack {Text("Regular Font Weight").fontWeight(.regular)Text("Bold Font Weight").fontWeight(.bold)}}}
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.