17

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)
3
  • 1
    Look at this topic stackoverflow.com/questions/56471973/… Commented Nov 5, 2019 at 6:59
  • Thanks. Is it the only option for now? There is still no simpler solution in SwiftUI? Commented Nov 5, 2019 at 7:00
  • Unfortunately, yes. Commented Nov 5, 2019 at 7:13

1 Answer 1

24

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.