0
0
iOS Swiftmobile~20 mins

Overlay and background modifiers in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Overlay and Background Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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))
AA blue circle with a thin red border inside
BA red circle with a blue border
CA blue circle with a thick red border around it
DA solid red circle with no border
Attempts:
2 left
💡 Hint
Remember that overlay places the new view on top of the original view.
ui_behavior
intermediate
2: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)
AText with yellow background and green background behind the yellow
BText with green background only
CText with yellow background only
DText with no background color
Attempts:
2 left
💡 Hint
Each background applies behind the view it modifies, including padding.
lifecycle
advanced
2: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))
AThe red circle is invisible because it has no frame
BThe red circle is 50x50 points centered on the 150x100 rectangle
CThe red circle stretches to fill the entire rectangle
DThe red circle is 150x100 points, same as the rectangle
Attempts:
2 left
💡 Hint
Overlay uses the size of the overlay view unless you specify a frame.
🔧 Debug
advanced
2: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)
  )
AThe stroke modifier causes the overlay to shift
BThe overlay circle frame is ignored and defaults to text size
CThe overlay modifier requires explicit alignment parameter to center
DThe overlay circle does not inherit the size of the text, so it aligns top-left by default
Attempts:
2 left
💡 Hint
Overlay aligns the overlay view to the top-left if sizes differ and no alignment is set.
🧠 Conceptual
expert
2:00remaining
Difference Between Overlay and Background
Which statement correctly describes the difference between overlay and background modifiers in SwiftUI?
AOverlay places a view on top of the original view; background places a view behind it
BOverlay replaces the original view; background adds a border around it
COverlay only works with shapes; background only works with colors
DOverlay and background are interchangeable and produce the same effect
Attempts:
2 left
💡 Hint
Think about layering: what is in front and what is behind?