Apilado vertical de vistas
Agrupe las vistas de arriba abajo con VStack.
Apilado vertical de vistas es una lección gratuita de SwiftUI Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de SwiftUI Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de SwiftUI Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 🎉
Preguntas frecuentes
¿La lección «Apilado vertical de vistas» es gratis?
Sí — el texto completo de «Apilado vertical de vistas» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de SwiftUI Academy, actualiza a CoddyKit PRO. El curso de SwiftUI Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Apilado vertical de vistas»?
Agrupe las vistas de arriba abajo con VStack. Practicas SwiftUI Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar SwiftUI Academy?
No se requiere experiencia previa. SwiftUI Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Apilado vertical de vistas»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de SwiftUI Academy?
Sí. Cada lección de SwiftUI Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Apilado vertical de vistas
- Filas con HStack
- Superposición con ZStack
- Espaciado y alineación en pilas