'SwiftUI header font

I'm trying to find a good way to get the system font for a List's header. Here's what I mean:

struct ContentView: View {
    var body: some View {
        List {
            Section(header: Text("Test")) {
                Text("Blablabla")
            }
        }
    }
}

enter image description here

Basically, is there a way to programmatically get the font for the text in the image that says "Test", so I can use it elsewhere in a Text object for example?

I'm font of the trying to make a collapsible header by using DisclosureGroup, however the font of the DisclosureGroup is different from the font of the Section.



Solution 1:[1]

For single use:

Section(header: Text("Test").font(.title)) {
    Text("Blablabla")
}

For multiple use:

First, Create a struct:

struct CustomFont: View {
    var body: some View {
        Text("Test")
           .font(.title)
    }
 }

Second, Call the instance of the struct to use it.

Section(header: CustomFont()) {
    Text("Blablabla")
}

Solution 2:[2]

another approach is to give the font you want, and then use that everywhere you want to, lots of fun:

Text("Test").font(.largeTitle)

Text("Test").font(.system(size:34))

Text("Test").font(.system(size: 20, weight: .bold, design: .serif)))

Text("Test").font(Font.custom("Wingdings", size: 30.0))

Text("Test").font(Font.custom("Montserrat-Bold", size: 30.0))

Solution 3:[3]

Section header's default font is .font(.headline). And the text is uppercased.

Text("Test".uppercased()).font(.headline)

https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 mahan