UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: How to set the colour of a section header

Forums > SwiftUI

How do I set the foreground colour of the header text of a section?

In the below example, it is just the header text "This is the heading" that I wish to change.

                        Section("This is the heading") {
                            Text("Text #1")
                            Text("Text #2")
                            Text("Text #3")
                        }
                        .listRowBackground(Color.clear)
                        .listRowSeparator(.hidden)

   

Just use another initializer for Section like so:

Section {
    Text("Text #1")
    Text("Text #2")
    Text("Text #3")
} header: {
    Text("This is the heading")
        .foregroundStyle(.red)
}

   

That did the trick nicely. Thank you. :-)

   

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.