Pick the fix
Show three buttons side by side if they fit, otherwise stacked vertically, including at large Dynamic Type sizes. Best tool?
Hint 1 of 1
Which API measures the options for you?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A ViewThatFits { HStack { buttons } ; VStack { buttons } }
Correct. It measures and picks the first layout that fits.
Why not the others?
- B GeometryReader and compare width with a magic number. It works but is fragile and greedy, and it ignores text size.
- C AnyLayout chosen by horizontalSizeClass. Size class doesn't tell you whether these buttons fit at the current text size.
- D Always use VStack. It wastes space when the buttons would fit.