Auto Layout vs. Manual Layout for Dynamic Type Support in Custom UI Elements
18.5K reputation · 03 Oct 2024, 00:35 UTC
Auto Layout vs. Manual Layout for Dynamic Type Support in Custom UI Elements
Goal: Make a custom component adjust its size and content when the user changes the system font size via Dynamic Type. The component contains multiple labels and icons that must remain legible and properly spaced.
Constraint: Auto Layout automatically respects intrinsicContentSize and UIContentSizeCategoryDidChangeNotification, but can cause layout thrashing if the constraint graph is large. Manual layout in layoutSubviews gives fine‑grained control and can be optimized, yet it requires careful recalculation of frames and can drift if font metrics are not updated.
Unresolved Decision: Which method balances performance, maintainability, and accessibility consistency for a component with dozens of subviews?
Specific Questions:
- For a view with 30 labels, which approach yields lower CPU usage during a Dynamic Type change?
- When using manual layout, what is the best practice to update
accessibilityElementsso VoiceOver reflects the new geometry? - Does Auto Layout provide any guarantees about preserving
accessibilityTraitsacross font size changes?