0
0
iOS Swiftmobile~20 mins

Frame modifier in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Frame Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the size of the red rectangle after applying the frame modifier?
Consider this SwiftUI code snippet:
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)
AWidth 100 points and height 50 points
BWidth and height fill the parent view
CWidth 50 points and height 100 points
DSize depends on the device screen size
Attempts:
2 left
💡 Hint
The frame modifier sets the exact size of the view.
ui_behavior
intermediate
2:00remaining
How does the frame modifier affect alignment inside a VStack?
Given this SwiftUI code:
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")
}
A"Hello" text aligned to the right inside the 200x50 frame
B"Hello" text centered inside the 200x50 frame
C"Hello" text aligned to the left inside the 200x50 frame
DAlignment has no effect inside frame modifier
Attempts:
2 left
💡 Hint
The alignment parameter controls content position inside the frame.
lifecycle
advanced
2:00remaining
What happens if you apply multiple frame modifiers with different sizes?
Analyze this SwiftUI code:
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)
AWidth 100 points and height 100 points (first frame applied)
BWidth 200 points and height 50 points (last frame applied)
CWidth 200 points and height 100 points (mixed sizes)
DCircle will fill the parent view ignoring frames
Attempts:
2 left
💡 Hint
Modifiers are applied in order, last one affects final size.
📝 Syntax
advanced
2:00remaining
Which frame modifier code snippet compiles without error?
Choose the correct SwiftUI frame modifier syntax from these options:
A.frame(width = 100, height = 50, alignment = .center)
B.frame(100, 50, .center)
C.frame(width: 100 height: 50 alignment: .center)
D.frame(width: 100, height: 50, alignment: .center)
Attempts:
2 left
💡 Hint
Swift function parameters use colons, not equals signs.
🧠 Conceptual
expert
3:00remaining
What is the effect of using .frame(maxWidth: .infinity, maxHeight: .infinity) on a view?
Consider this SwiftUI code:
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)
AThe Text view expands to fill all available space in both width and height
BThe Text view expands only vertically but not horizontally
CThe Text view expands only horizontally but not vertically
DThe Text view keeps its natural size and ignores maxWidth and maxHeight
Attempts:
2 left
💡 Hint
Using .infinity for maxWidth and maxHeight tells the view to grow as much as possible.