Adapt Layouts for Large Text
mainWhen text becomes very large, horizontal layouts (like HStack) often break. Use one of these three patterns to adapt your layout:
- Flip Stack Axis: Use
AnyLayoutto switch betweenHStackLayoutandVStackLayoutbased on thedynamicTypeSize. - Approach with Group: Use a
Groupwith anif/elseblock to switch betweenHStackandVStack. - ViewThatFits: Use
ViewThatFitsto let SwiftUI automatically pick the layout that fits the available space. This is ideal for local UI blocks and handles complex fallback logic better than simple size thresholds.
// ViewThatFits example
ViewThatFits {
HStack { content } // Try horizontal first
VStack { content } // Fall back to vertical
}