Bird
0
0

What will be the visible result of this SwiftUI code?

medium📝 ui behavior Q13 of 15
iOS Swift - SwiftUI Layout
What will be the visible result of this SwiftUI code?
ScrollView(.horizontal) {
  HStack {
    ForEach(1...3, id: \ .self) { i in
      Text("Item \(i)")
        .frame(width: 100, height: 100)
        .background(Color.blue)
        .foregroundColor(.white)
        .padding(5)
    }
  }
}
AThree blue boxes labeled Item 1, Item 2, Item 3 arranged horizontally and scrollable
BThree blue boxes arranged vertically with no scrolling
COnly one blue box visible with no scrolling
DError because ScrollView cannot scroll horizontally
Step-by-Step Solution
Solution:
  1. Step 1: Analyze ScrollView direction and content

    The ScrollView is horizontal, and inside is an HStack with three Text views styled as blue boxes.
  2. Step 2: Understand layout and scrolling

    HStack arranges items horizontally. ScrollView allows horizontal scrolling if content is wider than screen.
  3. Final Answer:

    Three blue boxes labeled Item 1, Item 2, Item 3 arranged horizontally and scrollable -> Option A
  4. Quick Check:

    Horizontal ScrollView + HStack = horizontal scroll [OK]
Quick Trick: Horizontal ScrollView + HStack = horizontal scrolling list [OK]
Common Mistakes:
  • Thinking items arrange vertically inside HStack
  • Assuming no scrolling happens
  • Believing horizontal scroll is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes