SwiftUI TextEditor .background()

Using XCode 12 Beta, setting the background on the new SwiftUI TextEditor() view doesn't seem to be working. Is this by design?

Code Block
TextEditor(text: $text)
.background(Color.red)
.foregroundColor(Color.black)

I have same problem too.
Yep, I would also like to be able to change the background color. There doesn't seem to be a way to customize it at the moment.
I have same problem too.
but you can setup .opacity(0.5) , will show background color(with opacity).

Code Block
TextEditor(text: $text)
        .background(Color.red)
        .foregroundColor(.black)
        .opacity(0.5)
        .padding()


if you want more red you can try

Code Block
 TextEditor(text: $text)
      .background(
        ZStack {
          Color.red
          Color.red
          Color.red
          Color.red
          Color.red
          Color.red
        }
      )
       
      .foregroundColor(.black)
      .opacity(0.5)
      .padding()



with iOS 16 you need to use scrollContentBackground. A user on SO created an extension method to handle both cases: https://stackoverflow.com/a/75910933/69144

I verified this worked for me

code from their answer below:


struct ContentView: View {
    @State private var editingText: String = ""    
    var body: some View {
        TextEditor(text: $editingText)
            .transparentScrolling()
            .background(Color.red)
    }
}

public extension View {
    func transparentScrolling() -> some View {
        if #available(iOS 16.0, *) {
            return scrollContentBackground(.hidden)
        } else {
            return onAppear {
                UITextView.appearance().backgroundColor = .clear
            }
        }
    }
}

SwiftUI TextEditor .background()
 
 
Q