I have the following and would like the longer text to wrap
Text("Long label that needs to be able to wrap but isn't doing it yet.")
.font(.largeTitle)
.multilineTextAlignment(.center)
.lineLimit(0)
Turns out you can pass nil
to the .lineLimit
and it will make the Text()
wrap as desired.
Text("Long label that needs to be able to wrap but isn't doing it yet.")
.font(.largeTitle)
.multilineTextAlignment(.center)
.lineLimit(nil)
I just tested this on the lastest XCode 11 beta, beta 7. I needed to specify a non-nil line limit and also use the padding
modifier in order to achieve multiline text
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.")
.font(.subheadline)
.multilineTextAlignment(.center)
.lineLimit(3)
.padding()
Both .fixedSize
and .lineLimit(nil)
should work.
Text("Label text")
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
OR
Text("Label text")
.multilineTextAlignment(.leading)
.lineLimit(nil)
.fixedSize
is the preferred/suggested option from Apple to word wrap the text into next line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With