Adding unlimited lines in a Text (SwiftUI) Adding unlimited lines in a Text (SwiftUI) ios ios

Adding unlimited lines in a Text (SwiftUI)


For wrapping Text in a Form .lineLimit(Int.max) did not work for me. It seems there needs to be some width for it to know when to wrap. I believe the official way is with .fixedSize:

Text(message)    .fixedSize(horizontal: false, vertical: true)

The documentation states:

This example shows the effect of fixedSize(horizontal:vertical:) on a text view that is wider than its parent, preserving the ideal, untruncated width of the text view.

https://developer.apple.com/documentation/swiftui/view/fixedsize(horizontal:vertical:)


Use .lineLimit() to limit the amount of lines of text. It takes an optional Int (Int?) as an argument, and .lineLimit(nil) allows unlimited lines.

Edit: As of SwiftUI Beta 5, Text has a default line limit of nil, so text in Text will wrap by default.


Use this:

Text("Ingredients: Avocado, Almond Butter, Bread")    .lineLimit(nil)

If that doesn't work, use this method:

Text("Ingredients: Avocado, Almond Butter, Bread")    .fixedSize(horizontal: false, vertical: true)