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?
The green rounded rectangle should be behind the text, so use .background() with RoundedRectangle.
Step 2: Add white text with shadow on top
The white text with shadow overlays on top, so use .overlay() with Text and modifiers.
Final Answer:
Text("Press") with green background and white shadowed overlay text. -> Option A
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
Master "SwiftUI Layout" in iOS Swift
9 interactive learning modes - each teaches the same concept differently