Bird
0
0

What will be the visible result of this SwiftUI code?

medium📝 Predict Output Q13 of 15
iOS Swift - SwiftUI Layout
What will be the visible result of this SwiftUI code?
Text("Hi")
  .background(Color.yellow)
  .overlay(Text("Overlay"))
AText "Hi" with yellow background and "Overlay" text on top
BText "Hi" with yellow background only, no overlay text
CText "Overlay" with yellow background, "Hi" hidden
DOnly yellow background visible, no text
Step-by-Step Solution
Solution:
  1. Step 1: Understand modifier order

    The .background(Color.yellow) adds a yellow color behind "Hi" text. Then .overlay(Text("Overlay")) places "Overlay" text on top.
  2. Step 2: Visual layering result

    Both texts are visible: "Hi" with yellow behind, and "Overlay" layered above.
  3. Final Answer:

    Text "Hi" with yellow background and "Overlay" text on top -> Option A
  4. Quick Check:

    Background behind, overlay on top = layered views [OK]
Quick Trick: Background is behind, overlay is on top, both visible [OK]
Common Mistakes:
  • Thinking overlay replaces original text
  • Ignoring modifier order effects
  • Assuming background covers overlay

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes