Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Texteditor in a form

Tags:

swiftui

I am creating a screen using a Form, with one TextField and one textEditor. Here is my code:

struct AddIssueView: View {

    @State var title = ""
    @State var description = "Enter issue description"

    var body: some View {
    
        NavigationView {
            Form {
                 Section(header: Text("Title")) {
                    TextField("Enter issue title", text: $title)
                 }
                
                 Section(header: Text("Description")) {
                    TextEditor(text: $description)
                 }
                 .navigationTitle("New Issue")
            
            }
        
        }
    
    }
}

This is the resulting screen - I find it surprising that the TextEditor UI looks like the TextField UI - I expected to see a multi-line text area. I'm not sure what I'm missing - any help will be most appreciated.

enter image description here

like image 623
bridgenbarbu Avatar asked Sep 06 '25 21:09

bridgenbarbu


1 Answers

Set the frame size on the TextEditor. Here are values I'm using in a project. Fiddle around with the values to get the size you'd like.

TextEditor(text: $postBody)
    .frame(minWidth: 200,
           idealWidth: 250,
           maxWidth: 400,
           minHeight: 300,
           idealHeight: 325,
           maxHeight: .infinity,
           alignment: .center)
like image 100
Gene De Lisa Avatar answered Sep 11 '25 02:09

Gene De Lisa