Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add Explnation Text under Form Toggle in Swift?UI

I’m trying to replicate a common view that I’ve seen in the iPhone settings where you can see some settings field and underneath it, there’s an explanation text:

enter image description here

I can’t find a way to add the explanation text below and make it look neat like Apple are doing:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

struct SomeView: View {
    @State private var someBool = true
    
    var body: some View {
        Form {
            Toggle("I am a toggle", isOn: $someBool)
            Text("This is not formatted well :(")
                .font(.caption)
                .foregroundColor(.gray)
        }
        .navigationBarTitle(Text("Some form"))
        .navigationBarTitleDisplayMode(.inline)
    }
    
}

Here’s the result:

enter image description here

>Solution :

Use section footer for that, like

    Form {
        Section {
            Toggle("I am a toggle", isOn: $someBool)
        } footer: {
            Text("This is not formatted well :(")   // << here !!
                .font(.caption)
                .foregroundColor(.gray)
        }
    }

Tested with Xcode 13.4 / iOS 15.5

demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading