0
0
iOS Swiftmobile~20 mins

Spacer and padding in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spacer and Padding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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")
}
AThe texts will overlap each other in the middle of the screen.
BThe texts "Left" and "Right" will be pushed to the edges of the screen with space between them.
CThe texts will be stacked tightly together in the center with no space between.
DThe texts will be aligned vertically instead of horizontally.
Attempts:
2 left
💡 Hint
Think about how Spacer expands to fill available space.
ui_behavior
intermediate
2: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()
AThe text disappears from the screen.
BThe text color changes to gray.
CThe text becomes bold and larger.
DThe text gets extra space around it inside its container, increasing the tappable area.
Attempts:
2 left
💡 Hint
Padding adds space inside the view's boundary.
lifecycle
advanced
2: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)
AThe total padding is 15 points on all sides.
BOnly the last padding(5) is applied, so 5 points total.
CThe padding values multiply, resulting in 50 points total.
DThe padding values conflict and cause a runtime error.
Attempts:
2 left
💡 Hint
Modifiers stack and add up in SwiftUI.
📝 Syntax
advanced
2: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()
}
APadding cannot take numeric arguments.
BSpacer cannot be used inside VStack.
CMissing closing parenthesis in .padding(10).
DText must be inside a HStack, not VStack.
Attempts:
2 left
💡 Hint
Check the parentheses carefully.
🧠 Conceptual
expert
2: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?
ASpacer automatically adjusts to fill available space, making layouts responsive to screen size changes.
BSpacer reduces app memory usage compared to padding.
CSpacer changes the font size of text automatically.
DSpacer disables user interaction on views.
Attempts:
2 left
💡 Hint
Think about how layouts adapt on different devices.