Views vertikal stapeln
Gruppieren Sie Views mit VStack von oben nach unten.
Views vertikal stapeln ist eine kostenlose SwiftUI Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des SwiftUI Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Why You Need Stacks
A SwiftUI body can return only one view. To show several views together, you wrap them in a container that arranges them for you. 📦
Meet VStack
A VStack stacks its child views vertically, top to bottom. It is your go-to container for column-style layouts like a title above a subtitle.
Your First VStack
Place views inside the VStack braces and they appear in order, each on its own line. The first child sits at the top.
VStack {
Text("Hello")
Text("World")
}Order Matters
Children render in the exact order you write them. Swap two lines of code and the views swap places on screen. Top of the code is top of the column.
Centered by Default
By default a VStack centers its children horizontally and shrinks to fit its content, like a tidy little column hugging its views.
Mixing View Types
A VStack does not care what kind of views it holds. You can freely mix a Text, an Image, and a Button in the same vertical stack.
VStack {
Image(systemName: "star")
Text("Favorite")
}How Many Views Fit?
A stack can hold up to ten direct children at once. That is plenty for most screens, and you can always nest stacks for more.
Nesting Stacks
You can put a VStack inside another VStack to build richer layouts. Nesting lets you group related views so they move together.
VStack {
Text("Title")
VStack {
Text("Line 1")
Text("Line 2")
}
}Stacks Are Views Too
A VStack is itself a view, so you can apply modifiers like padding or background to the whole stack at once. The group acts as one unit.
Returning a VStack from body
Since body needs a single view, returning a VStack is the classic way to show many views. The stack becomes that one returned view.
var body: some View {
VStack {
Text("One")
Text("Two")
}
}When to Reach for VStack
Use a VStack whenever items should read top to bottom: a heading over body text, a label over a value, or a form laid out in rows.
Quick Check
Let's make sure VStack ordering is clear.
Recap: Vertical Stacking
Nice work! A VStack arranges views top to bottom in code order, centers them by default, and acts as one view you can style or nest. 🎉
Lerne Swift mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 30
- Lektionen
- 120
Häufig gestellte Fragen
Ist die Lektion „Views vertikal stapeln“ kostenlos?
Ja — der vollständige Text von „Views vertikal stapeln“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des SwiftUI Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Views vertikal stapeln“?
Gruppieren Sie Views mit VStack von oben nach unten. Du übst SwiftUI Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um SwiftUI Academy zu starten?
Keine Vorkenntnisse erforderlich. SwiftUI Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Views vertikal stapeln“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser SwiftUI Academy-Lektion Code schreiben und ausführen?
Ja. Jede SwiftUI Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Views vertikal stapeln
- Zeilen mit HStack
- Views mit ZStack überlagern
- Abstände und Ausrichtung in Stacks