swiftswiftuilayoutuikit

Dynamic Layout in SwiftUI


I’m looking for an API or modifier in SwiftUI that allows dynamic layout similar to CSS Flexbox. Specifically, I’m trying to achieve a layout where content aligns horizontally if there’s enough width, and automatically switches to a vertical alignment if the available width is limited.

I seem to remember seeing a layout method that enables this kind of behavior, possibly introduced recently by Apple. However, I can’t recall the exact name of this method, and I’d prefer to avoid implementing a custom layout if an official method already exists.

Does anyone know the name of this method, or am I just remembering an ideal layout that only exists in a dream?

Thank you!


Solution

  • Use ViewThatfits

    https://developer.apple.com/documentation/swiftui/viewthatfits

    Thanks to your comment, I was able to find this API