How to change the background color of TextEditor like TextField

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

How to change the background color of TextEditor like TextFeild

Change background color of TextEditor in SwiftUI

Background color not change TextEditor view

Change TextField background Color based on the TextField state

SwiftUI how to change background color for TextField on Light theme (appearance)?

Ubuntu SDK QML how to change the background color of TextField

material ui, how to change background color, font color, border color of autocomplete textfield

Change background color on TextField when focused

safari textfield background color wont change

How to change background color of NSSearchField (like in Messages app in OS X)

how to change UISearchBar textfield background color and text color in ios8

How to change textField underline color?

How to change textfield color (Vaadin)

How to change the color of the TextField selection

How to change text color at ICSharpCode.AvalonEdit.TextEditor?

How to change the background color

How to invert text color in TextField depending on background

How to remove background color of TextField on Flutter Widget?

SwiftUI: How to set background color for textfield

How do you change the background color of a TextField without changing the border in javafx?

SwiftUI Textfield - How to set the background Color for textfield in edit mode to clear

Changing TextEditor background color in SwiftUI for macOS

Change TextField (MUI) background color when data present

Material-UI: Change autofill background color in TextField

Ionic - how to change textfield background colour?

Textfield background color not changing

How to change UIBezierPath background color?

How to change a background color for a row

How to change FAB background color