Bird
0
0

What will be the visual arrangement of views in this SwiftUI code snippet?

medium📝 Predict Output Q4 of 15
iOS Swift - SwiftUI Basics
What will be the visual arrangement of views in this SwiftUI code snippet?
VStack {
  Text("Top")
  Spacer()
  Text("Bottom")
}
ATexts overlap each other in the center.
BBoth texts are stacked tightly at the center with no space.
C"Bottom" text appears above "Top" text.
DThe "Top" text is at the top, "Bottom" text is at the bottom with space in between.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze VStack with Spacer()

    VStack arranges views vertically. Spacer() expands to fill space.
  2. Step 2: Layout Effect

    "Top" text is placed at the top, Spacer pushes "Bottom" text to the bottom.
  3. Final Answer:

    The "Top" text is at the top, "Bottom" text is at the bottom with space in between. -> Option D
  4. Quick Check:

    Spacer pushes views apart vertically in VStack. [OK]
Quick Trick: Spacer() pushes views apart in stacks [OK]
Common Mistakes:
  • Assuming Spacer() adds fixed space instead of flexible
  • Thinking views overlap or reorder
  • Ignoring Spacer's effect on layout

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes