Bird
0
0

What will be the size of the red rectangle on screen after applying this code?

medium📝 Predict Output Q13 of 15
iOS Swift - SwiftUI Layout
What will be the size of the red rectangle on screen after applying this code?
Rectangle()
  .fill(Color.red)
  .frame(width: 150, height: 100)
  .frame(width: 200, height: 200)
A200 width and 200 height
B150 width and 100 height
C350 width and 300 height
D100 width and 150 height
Step-by-Step Solution
Solution:
  1. Step 1: Understand frame stacking

    Each frame modifier wraps the view with a new size. The last frame sets the final size.
  2. Step 2: Analyze the code

    The first frame sets 150x100, but the second frame wraps that with 200x200, so the final size is 200x200.
  3. Final Answer:

    200 width and 200 height -> Option A
  4. Quick Check:

    Last frame modifier sets final size [OK]
Quick Trick: Last frame modifier determines final size [OK]
Common Mistakes:
  • Adding widths and heights of stacked frames
  • Assuming first frame size remains final
  • Confusing fill color with size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes