Challenge - 5 Problems
Alignment and Spacing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Understanding SwiftUI VStack Alignment
What will be the horizontal alignment of the text views inside this VStack by default?
iOS Swift
VStack {
Text("Hello")
Text("World")
}Attempts:
2 left
💡 Hint
Think about the default alignment behavior of VStack in SwiftUI.
✗ Incorrect
By default, VStack aligns its children views horizontally centered unless specified otherwise.
❓ ui_behavior
intermediate2:00remaining
Spacing in HStack
Given this HStack, what is the space between the two Text views?
iOS Swift
HStack(spacing: 20) { Text("Left") Text("Right") }
Attempts:
2 left
💡 Hint
Look at the spacing parameter in the HStack initializer.
✗ Incorrect
The spacing parameter sets the exact space between child views in the stack. Here it is 20 points.
❓ lifecycle
advanced2:00remaining
Effect of Padding on View Size
What happens to the size of a SwiftUI Text view when you add .padding() modifier?
iOS Swift
Text("Hello")
.padding()Attempts:
2 left
💡 Hint
Padding adds empty space around the content inside the view.
✗ Incorrect
Padding adds space inside the view's bounds around its content, increasing the overall size.
📝 Syntax
advanced2:00remaining
Correct Syntax for Center Alignment in VStack
Which option correctly centers all child views horizontally inside a VStack?
Attempts:
2 left
💡 Hint
Check the valid alignment options for VStack.
✗ Incorrect
The .center alignment centers child views horizontally inside VStack. Other options align differently or are invalid.
🔧 Debug
expert2:00remaining
Fixing Unexpected Spacing in SwiftUI Layout
You have this code but notice extra space around the Text view. What causes it?
iOS Swift
VStack {
Text("Hello")
.padding(.horizontal, 30)
Text("World")
}Attempts:
2 left
💡 Hint
Padding adds space inside the view's bounds around content.
✗ Incorrect
The horizontal padding adds 30 points on each side of the Text, increasing its width and space around it.