Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Text View in SwiftUI [duplicate]

Tags:

ios

swift

swiftui

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")     } } 

enter image description here

like image 860
Bilal Avatar asked Jun 12 '19 08:06

Bilal


People also ask

How do you show multiple lines of text in SwiftUI?

To force a minimum number of lines to a text view, you append a new line character ( \n ) to your text.

How do I know if a text is truncated SwiftUI?

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.

What is multiline text?

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.


1 Answers

You can use the answer from comments, thx to https://stackoverflow.com/users/8642838/jonas-deichelmann

.fixedSize(horizontal: false, vertical: true) 
like image 81
Viktor Gardart Avatar answered Sep 20 '22 18:09

Viktor Gardart