How can i make this TextEditor text appear on fullscreen, unlike inside this scrolling frame

111 views Asked by At

I am trying to display this text inside TextEditor in full screen but it is showingup inside this scrolling frame. I've tried this method .fixedSize(horizontal: false, vertical: true) on TextEditor View but it didn't help.

I’ve shared this preview:

enter image description here

import SwiftUI

struct TempView: View {
    @State private var sampleText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
    var body: some View {
        ScrollView() {
            VStack() {
                TextEditor(text: $sampleText)
                    .font(.largeTitle)
                    .background(Color.blue)
            }
            .background(Color.blue)
        }
    }
}
1

There are 1 answers

5
Steven-Carrot On

Edit: I included one more solution in this answer. Code is below the image.

enter image description here

import SwiftUI

struct TempView: View {
let screenSize: CGFloat = UIScreen.main.bounds.size.height
@State private var sampleText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
var body: some View {
    ScrollView {
        Text("Welcome to my app")
            .font(.title2)
            .foregroundColor(.blue)
        
        //this is how much percentage you want your TextEditor
        //to fill the height of your screen
        //you can go as high as how much you want the TextEditor to fill the screen
        TextEditor(text: $sampleText)
            .frame(minHeight: screenSize * 0.7) //this
            .font(.largeTitle)
        
        ForEach(0...5, id: \.self) { _ in
            HStack {
                Text("Made on July 2022")
                    .padding()
                    .foregroundColor(.blue)
                Spacer()
                Text("Made by me")
                    .padding()
                    .foregroundColor(.blue)
            }
        }
    }
    .padding(.top)
 
  }
}

However, if you want to display just your TextEditor in full screen, you don't need the ScrollView because TextEditor has its own supported scroll already.

import SwiftUI

struct TempView: View {
@State private var sampleText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
var body: some View {
    TextEditor(text: $sampleText)
        .font(.largeTitle)
        .background(Color.blue)
        .edgesIgnoringSafeArea(.all) //added
        .padding(.top) //added
}
}