Bird
0
0

How can you create a horizontal stack inside a vertical stack in SwiftUI?

hard📝 Application Q9 of 15
iOS Swift - SwiftUI Basics
How can you create a horizontal stack inside a vertical stack in SwiftUI?
AZStack { VStack { Text("Top") Text("Bottom") } HStack { Text("Left") Text("Right") } }
BVStack { Text("Top") HStack { Text("Left") Text("Right") } Text("Bottom") }
CHStack { VStack { Text("Top") Text("Bottom") } Text("Left") Text("Right") }
DVStack { HStack(Text("Left"), Text("Right")) Text("Top") Text("Bottom") }
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested stacks

    You can place an HStack inside a VStack to combine layouts.
  2. Step 2: Check syntax and order

    VStack { Text("Top") HStack { Text("Left") Text("Right") } Text("Bottom") } correctly nests HStack inside VStack with proper braces and views.
  3. Final Answer:

    VStack { Text("Top") HStack { Text("Left") Text("Right") } Text("Bottom") } -> Option B
  4. Quick Check:

    Nested HStack inside VStack uses braces correctly [OK]
Quick Trick: Nest stacks by placing one inside another's braces [OK]
Common Mistakes:
  • Using parentheses instead of braces for nested stacks
  • Placing views outside stack braces
  • Confusing order of nested stacks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes