Challenge - 5 Problems
Frame Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the size of the red rectangle after applying the frame modifier?
Consider this SwiftUI code snippet:
What will be the size of the red rectangle displayed on screen?
Rectangle() .fill(Color.red) .frame(width: 100, height: 50)
What will be the size of the red rectangle displayed on screen?
iOS Swift
Rectangle() .fill(Color.red) .frame(width: 100, height: 50)
Attempts:
2 left
💡 Hint
The frame modifier sets the exact size of the view.
✗ Incorrect
The frame modifier with width and height sets the view's size explicitly to those values.
❓ ui_behavior
intermediate2:00remaining
How does the frame modifier affect alignment inside a VStack?
Given this SwiftUI code:
How will the "Hello" text be aligned inside its frame?
VStack {
Text("Hello")
.frame(width: 200, height: 50, alignment: .leading)
Text("World")
}How will the "Hello" text be aligned inside its frame?
iOS Swift
VStack {
Text("Hello")
.frame(width: 200, height: 50, alignment: .leading)
Text("World")
}Attempts:
2 left
💡 Hint
The alignment parameter controls content position inside the frame.
✗ Incorrect
The alignment: .leading parameter aligns the text to the left inside the frame.
❓ lifecycle
advanced2:00remaining
What happens if you apply multiple frame modifiers with different sizes?
Analyze this SwiftUI code:
What will be the final size of the Circle on screen?
Circle() .frame(width: 100, height: 100) .frame(width: 200, height: 50)
What will be the final size of the Circle on screen?
iOS Swift
Circle() .frame(width: 100, height: 100) .frame(width: 200, height: 50)
Attempts:
2 left
💡 Hint
Modifiers are applied in order, last one affects final size.
✗ Incorrect
The last frame modifier sets the final size to width 200 and height 50.
📝 Syntax
advanced2:00remaining
Which frame modifier code snippet compiles without error?
Choose the correct SwiftUI frame modifier syntax from these options:
Attempts:
2 left
💡 Hint
Swift function parameters use colons, not equals signs.
✗ Incorrect
Option D uses correct parameter syntax with colons and commas.
🧠 Conceptual
expert3:00remaining
What is the effect of using .frame(maxWidth: .infinity, maxHeight: .infinity) on a view?
Consider this SwiftUI code:
What will be the behavior of the Text view inside its parent?
Text("Stretch me")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.blue)What will be the behavior of the Text view inside its parent?
iOS Swift
Text("Stretch me")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.blue)Attempts:
2 left
💡 Hint
Using .infinity for maxWidth and maxHeight tells the view to grow as much as possible.
✗ Incorrect
Setting maxWidth and maxHeight to .infinity makes the view expand to fill all available space in its parent container.