Bird
0
0

You want to create a button with a green rounded rectangle background and a white text overlay with shadow. Which SwiftUI code correctly achieves this?

hard📝 Application Q8 of 15
iOS Swift - SwiftUI Layout
You want to create a button with a green rounded rectangle background and a white text overlay with shadow. Which SwiftUI code correctly achieves this?
AText("Press") .background(RoundedRectangle(cornerRadius: 10).fill(Color.green)) .overlay(Text("Press").foregroundColor(.white).shadow(radius: 2))
BText("Press") .overlay(RoundedRectangle(cornerRadius: 10).fill(Color.green)) .background(Text("Press").foregroundColor(.white).shadow(radius: 2))
CText("Press") .background(Text("Press").foregroundColor(.white).shadow(radius: 2)) .overlay(RoundedRectangle(cornerRadius: 10).fill(Color.green))
DText("Press") .overlay(Text("Press").foregroundColor(.black).shadow(radius: 2)) .background(RoundedRectangle(cornerRadius: 10).fill(Color.green))
Step-by-Step Solution
Solution:
  1. Step 1: Place background shape behind text

    The green rounded rectangle should be behind the text, so use .background() with RoundedRectangle.
  2. Step 2: Add white text with shadow on top

    The white text with shadow overlays on top, so use .overlay() with Text and modifiers.
  3. Final Answer:

    Text("Press") with green background and white shadowed overlay text. -> Option A
  4. Quick Check:

    Background shape behind, overlay text on top = Text("Press") .background(RoundedRectangle(cornerRadius: 10).fill(Color.green)) .overlay(Text("Press").foregroundColor(.white).shadow(radius: 2)) [OK]
Quick Trick: Background behind, overlay on top for layered effects [OK]
Common Mistakes:
  • Swapping overlay and background roles
  • Duplicating text incorrectly
  • Placing text in background instead of overlay

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes