Combine views in SwiftUI

Hi there,

I am still quite new to Swift and want to combine a few views into one single view. But the problem is, that if I do it like in the following code, there are windows for each view. Is there a chance to code it that it is one coherent view where I can scroll through?

Thank you for your help!

Laurin

    @AppStorage("MediAnsicht") var MedisEinfacheAnsicht = false
    var body: some View {
        if MedisEinfacheAnsicht == true {
                AcetylsalicylsaeureAllgInfos()
                AcetylsalicylsaeureKontraind()
                AcetylsalicylsaeureUAWs()
        } else {
            AcetylsalicylsaeureMenu()
        }
    }
}

Answered by rinuality in 770871022

@shipty Thank you for your answer! Unfortunately the result did not look as I hoped. I found a solution. Instead of using ScrollView I could use Form, like this:

    @AppStorage("MediAnsicht") var MedisEinfacheAnsicht = false
    var body: some View {
        if MedisEinfacheAnsicht == true {
            Form {
                Section {
                    Image("AcetylsalicylsaeureMediLabel")
                        .resizable()
                        .scaledToFit()
                    NavigationLink(destination: AcetylsalicylsaeureSAA()){
                        Text("SAA anzeigen")
                            .foregroundColor(Color("SAAColor"))
                    }
                }
                AcetylsalicylsaeureAllgInfos()
                AcetylsalicylsaeureKontraind()
                AcetylsalicylsaeureUAWs()
                AcetylsalicylsaeureInd()
                AcetylsalicylsaeureDurchDo()
                AcetylsalicylsaeureAltBeg()
                AcetylsalicylsaeureBesond()
                AcetylsalicylsaeureVerlKon()
                AcetylsalicylsaeureErfPr()
                AcetylsalicylsaeureFoMass()
            }
        } else {
            AcetylsalicylsaeureMenu()
        }
    }
}

When I use ScrollView, it looks like this:

With Form it looks like this:

But thank you so much for your help! :)

Laurin

From my understanding of your question I think what you're looking for is ScrollView.

Just wrap all the views in a ScrollView and you'll get one coherent, scrollable view.

Like so:

 @AppStorage("MediAnsicht") var MedisEinfacheAnsicht = false
    var body: some View {
        if MedisEinfacheAnsicht == true {
            ScrollView {
                AcetylsalicylsaeureAllgInfos()
                AcetylsalicylsaeureKontraind()
                AcetylsalicylsaeureUAWs()
            }
        } else {
            AcetylsalicylsaeureMenu()
        }
    }
}
Accepted Answer

@shipty Thank you for your answer! Unfortunately the result did not look as I hoped. I found a solution. Instead of using ScrollView I could use Form, like this:

    @AppStorage("MediAnsicht") var MedisEinfacheAnsicht = false
    var body: some View {
        if MedisEinfacheAnsicht == true {
            Form {
                Section {
                    Image("AcetylsalicylsaeureMediLabel")
                        .resizable()
                        .scaledToFit()
                    NavigationLink(destination: AcetylsalicylsaeureSAA()){
                        Text("SAA anzeigen")
                            .foregroundColor(Color("SAAColor"))
                    }
                }
                AcetylsalicylsaeureAllgInfos()
                AcetylsalicylsaeureKontraind()
                AcetylsalicylsaeureUAWs()
                AcetylsalicylsaeureInd()
                AcetylsalicylsaeureDurchDo()
                AcetylsalicylsaeureAltBeg()
                AcetylsalicylsaeureBesond()
                AcetylsalicylsaeureVerlKon()
                AcetylsalicylsaeureErfPr()
                AcetylsalicylsaeureFoMass()
            }
        } else {
            AcetylsalicylsaeureMenu()
        }
    }
}

When I use ScrollView, it looks like this:

With Form it looks like this:

But thank you so much for your help! :)

Laurin

Combine views in SwiftUI
 
 
Q