How to change the background color of TextEditor like TextFeild

T-BM
struct TextView: View {
    @State private var textInput2: String = ""
    var body: some View {
        ScrollView{
            VStack(spacing: 24){
                TextField("", text: $textInput2)
                    .font(.body)
                    .foregroundColor(.gray)
                    .padding()
                    .frame(height: 142)
                    .background(Color("3"))
                    .cornerRadius(20)
                    .overlay(
                        RoundedRectangle(cornerRadius: 20)
                            .stroke(Color.gray.opacity(0.5), lineWidth: 2)
                    )
                
                TextEditor(text: $textInput2)
                    .textFieldStyle(PlainTextFieldStyle())
                    .font(.body)
                    .foregroundColor(.gray)
                    .padding()
                    .background(Color("3"))
                    .frame(height: 142)
                    .cornerRadius(20)
                    .overlay(
                        RoundedRectangle(cornerRadius: 20)
                            .stroke(Color.gray.opacity(0.5), lineWidth: 2)
                    )
            }
            .padding(.horizontal)
        }
    }
}

I want to change the background color of a TextEditor, I tried:

  • .foregroundColor changed the text color instead of the background color;
  • .background only changed the surroundings' background color and not the whole TextEditor as seen in the image below:

enter image description here

Miraj

Add this line to TextEditor:

.scrollContentBackground(.hidden) // <- Hide it

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related