Home > Mobile >  SwiftUI Text ignoring newline and tab characters
SwiftUI Text ignoring newline and tab characters

Time:05-11

I am attempting to render a multiline text block in SwiftUI using the Text component. I'm passing it a string that contains newlines and tabs, however whenever it is rendered, all of these special characters appear to be removed from text and the content is all rendered in a straight line. Does anyone have any ideas how to convince SwiftUI to actually let this be multiple lines?

let s = {\n\t\"hey\":\"there\"\n\n\n}
Text(.init("`\(s)`"))

The above code renders as:

Screenshot of the straight line

CodePudding user response:

From the docs modify your code accordingly.

Ex.

Text(“In SwiftUI Multiline text is great. \n Right?”)
         .lineLimit(nil)

CodePudding user response:

this works for me:

let s = "{\n\t\"hey\":\"there\"\n\n\n}"

Text("`\(s)`")

or

 Text("\(s)")

or

Text(s)
  • Related