Bird
0
0

You want a button to have a fixed width of 200 points but flexible height that fits its content. Which frame modifier should you use?

hard📝 Application Q8 of 15
iOS Swift - SwiftUI Layout
You want a button to have a fixed width of 200 points but flexible height that fits its content. Which frame modifier should you use?
A.frame(width: 200, height: .infinity)
B.frame(minWidth: 200, maxHeight: .infinity)
C.frame(width: 200)
D.frame(maxWidth: 200)
Step-by-Step Solution
Solution:
  1. Step 1: Fix width only

    Setting width: 200 fixes the width to 200 points.
  2. Step 2: Leave height flexible

    Not specifying height lets it adjust to content size.
  3. Final Answer:

    .frame(width: 200) -> Option C
  4. Quick Check:

    Specify only width for fixed width and flexible height = B [OK]
Quick Trick: Specify only width to fix width, keep height flexible [OK]
Common Mistakes:
  • Setting height to infinity causes errors
  • Using maxWidth instead of width
  • Specifying minWidth unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes