12

What is the equivalent of textarea in SwiftUI? Where I could have multiple lines of text input. And specify size of this area? HTML example is here: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea I have searched a lot without any luck.

I have tried to use TextField in SwiftUI, but if user writes long text, the text goes out of the screen.

TextField("notes")
.background(Color.yellow)
.lineLimit(3)
mallow
  • 2,368
  • 2
  • 22
  • 63

1 Answers1

14

The equivalent of TextArea in SwiftUI is TextEditor. Apple introduced it in mid 2020

var body: some View {
    TextEditor(text: $profileText)
        .foregroundColor(.black)
}

Here is a reference that describes it in more detail: https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-multi-line-editable-text-with-texteditor

Răzvan Rujoiu
  • 1,145
  • 12
  • 18