How to set Text
View to display text in multiple lines? By default it's 1 line.
struct ContentView : View { var body: some View { Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse est leo, vehicula eu eleifend non, auctor ut arcu") } }
To force a minimum number of lines to a text view, you append a new line character ( \n ) to your text.
You can use a GeometryReader to determine the width of the text field and then use that together with information about the font to calculate the size of the bounding rect that would be required to show the entire text. If that height exceeds the text view then we know that the text has been truncated.
The Multiline Text Field can be used to store larger amounts of text. The Multiline Text Field offers a lot of formatting options, such as: Adding bulleted and numbered lists. Use bold, italics and underline styling. Change the text format and size.
You can use the answer from comments, thx to https://stackoverflow.com/users/8642838/jonas-deichelmann
.fixedSize(horizontal: false, vertical: true)
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