fontweight swiftui in swift

To set the font weight in SwiftUI, you need to use the .fontWeight() modifier.

Here's an example of how to change the font weight to bold:

main.swift
Text("Hello, World!")
    .fontWeight(.bold)
45 chars
3 lines

You can also set the font weight to other values, such as regular, semibold, medium, and light:

main.swift
Text("Hello, World!")
    .fontWeight(.regular)
    
Text("Hello, World!")
    .fontWeight(.semibold)
    
Text("Hello, World!")
    .fontWeight(.medium)
    
Text("Hello, World!")
    .fontWeight(.light)
205 chars
12 lines

Make sure to import SwiftUI at the top of your Swift file:

main.swift
import SwiftUI
15 chars
2 lines

And don't forget to assign the modifier to a view, such as a Text view in this example.

gistlibby LogSnag