SwiftUI header font

Viewed 1040

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.

3 Answers

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")
}

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))
Related