4

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

1
  • 4
    It looks like when using a Form/ List or ScrollView, SwiftUI automatically inferred the height for your TextEditor, to fix that you can give a height to your TextEditor Commented Jul 22, 2021 at 14:23

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.