SwiftUI .fontWeight()

Christine_Yang's avatar
Published Feb 18, 2023Updated Mar 2, 2023
Contribute to Docs

The .fontWeight() modifier sets the font weight of the text in Text View.

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours

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 SwiftUI
struct SomeView: View {
var body: some View {
VStack {
Text("Regular Font Weight")
.fontWeight(.regular)
Text("Bold Font Weight")
.fontWeight(.bold)
}
}
}

This will display:

SwiftUI ViewModifier .fontWeight()

All contributors

Contribute to Docs

Learn SwiftUI on Codecademy

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours