Challenge - 5 Problems
Overlay and Background Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Overlay Modifier Behavior
What will be the visible color of the circle after applying the overlay modifier in this SwiftUI code?
iOS Swift
Circle() .fill(Color.blue) .frame(width: 100, height: 100) .overlay(Circle().stroke(Color.red, lineWidth: 10))
Attempts:
2 left
💡 Hint
Remember that overlay places the new view on top of the original view.
✗ Incorrect
The overlay modifier places the red stroked circle on top of the blue filled circle, so you see a blue circle with a red border.
❓ ui_behavior
intermediate2:00remaining
Background Modifier Effect
What will be the background color behind the text in this SwiftUI code?
iOS Swift
Text("Hello")
.padding()
.background(Color.yellow)
.padding()
.background(Color.green)Attempts:
2 left
💡 Hint
Each background applies behind the view it modifies, including padding.
✗ Incorrect
The first background applies yellow behind the padded text. The second background applies green behind the entire view including the first padding and background.
❓ lifecycle
advanced2:00remaining
Overlay Modifier and View Size
Given this SwiftUI code, what is the size of the overlay circle relative to the base rectangle?
iOS Swift
Rectangle() .fill(Color.gray) .frame(width: 150, height: 100) .overlay(Circle().fill(Color.red).frame(width: 50, height: 50))
Attempts:
2 left
💡 Hint
Overlay uses the size of the overlay view unless you specify a frame.
✗ Incorrect
The overlay circle has an explicit frame of 50x50 points, so it appears centered and smaller than the 150x100 rectangle.
🔧 Debug
advanced2:00remaining
Unexpected Overlay Position
Why does this overlay appear shifted to the top-left instead of centered?
iOS Swift
Text("SwiftUI") .overlay( Circle() .stroke(Color.blue, lineWidth: 3) .frame(width: 100, height: 100) )
Attempts:
2 left
💡 Hint
Overlay aligns the overlay view to the top-left if sizes differ and no alignment is set.
✗ Incorrect
Because the overlay circle has a fixed frame larger than the text, it aligns top-left by default, causing the shift.
🧠 Conceptual
expert2:00remaining
Difference Between Overlay and Background
Which statement correctly describes the difference between overlay and background modifiers in SwiftUI?
Attempts:
2 left
💡 Hint
Think about layering: what is in front and what is behind?
✗ Incorrect
Overlay adds a view on top of the original view, while background adds a view behind it, affecting layering order.