SwiftUI. How to wrap content in View

Artem Mihelson
Mar 29, 2022

--

Hi! Another short how-to on SwiftUI.

If you ever faced the question: “How to make SwiftUI view wrap its content?”. The answer is simple:

Text("Hello World!")
.padding(16)
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)

Such a modifier for Text view will make it wrap its content inside your view, no matter where you place it.

That’s it. Happy coding!

--

--

Artem Mihelson

Founder of Pills.Kit, Proximodoro and WidgetLingo apps