Reputation: 2866
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)
Upvotes: 17
Views: 12901
Reputation: 1475
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
Upvotes: 24