Challenge - 5 Problems
Spacer and Padding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
How does Spacer affect layout in SwiftUI?
Consider a horizontal stack with two Text views and a Spacer between them. What will be the visual result?
iOS Swift
HStack {
Text("Left")
Spacer()
Text("Right")
}Attempts:
2 left
💡 Hint
Think about how Spacer expands to fill available space.
✗ Incorrect
Spacer in SwiftUI expands to fill all available space in the stack's direction, pushing views apart to the edges.
❓ ui_behavior
intermediate2:00remaining
What effect does padding() have on a SwiftUI view?
Given a Text view with .padding() modifier, what changes visually?
iOS Swift
Text("Hello")
.padding()Attempts:
2 left
💡 Hint
Padding adds space inside the view's boundary.
✗ Incorrect
Padding adds empty space around the content inside the view's frame, making it larger and easier to interact with.
❓ lifecycle
advanced2:00remaining
What happens if you apply multiple padding modifiers in SwiftUI?
Consider this code:
Text("Hello")
.padding(10)
.padding(5)
What is the total padding around the text?
iOS Swift
Text("Hello") .padding(10) .padding(5)
Attempts:
2 left
💡 Hint
Modifiers stack and add up in SwiftUI.
✗ Incorrect
Each padding modifier adds space around the view. They accumulate, so 10 + 5 = 15 points total padding.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this SwiftUI padding code
What is wrong with this code snippet?
VStack {
Text("Hello")
.padding(10
Spacer()
}
iOS Swift
VStack {
Text("Hello")
.padding(10
Spacer()
}Attempts:
2 left
💡 Hint
Check the parentheses carefully.
✗ Incorrect
The .padding(10 modifier is missing a closing parenthesis, causing a syntax error.
🧠 Conceptual
expert2:00remaining
Why use Spacer instead of fixed padding for flexible layouts?
Which reason best explains why Spacer is preferred over fixed padding values for spacing in SwiftUI layouts?
Attempts:
2 left
💡 Hint
Think about how layouts adapt on different devices.
✗ Incorrect
Spacer expands to fill available space dynamically, allowing flexible and adaptive layouts unlike fixed padding.