Bird
0
0

What will be the visible result of this SwiftUI code?

medium📝 Predict Output Q5 of 15
iOS Swift - SwiftUI Layout
What will be the visible result of this SwiftUI code?
Text("Tap Me")
  .overlay(Rectangle().stroke(Color.blue, lineWidth: 3))
AOnly the text "Tap Me" with no border.
BA blue rectangle border on top of the text "Tap Me".
CA blue rectangle behind the text "Tap Me".
DA filled blue rectangle covering the text.
Step-by-Step Solution
Solution:
  1. Step 1: Understand .overlay() with Rectangle stroke

    The Rectangle with stroke modifier draws a border on top of the Text view.
  2. Step 2: Confirm overlay behavior

    Overlay places the rectangle border above the text, not behind or filled.
  3. Final Answer:

    A blue rectangle border on top of the text "Tap Me". -> Option B
  4. Quick Check:

    Overlay adds view on top = A blue rectangle border on top of the text "Tap Me". [OK]
Quick Trick: Use overlay for borders or highlights on top [OK]
Common Mistakes:
  • Thinking overlay places view behind
  • Confusing stroke with fill
  • Expecting no visible border

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes