0

Very annoying issue. I have a text editor that I am using within a ZStack stack so that it will grow as the user types. I am trying to set the background color of it, but it is just showing as a transparent box within the list. Any tips on how to set the color? (code has been reduced for clarity). Adding the background color in the init method DOES NOT WORK HERE

my view:

struct AddItem: View {
var body: some View {
   NavigationView {
      VStack {
      ...
        List {
          ZStack {
            Text(viewModel.description).opacity(0).listRowSeparator(.hidden)
            TextEditor(text: $viewModel.description)
            .onAppear() {
              UITextView.appearance().backgroundColor = .clear
            }
            .listRowSeparator(.hidden)
            .background(RoundedRectangle(cornerRadius: 25.0).fill(Color(.systemGray6))) // this doesn't work. nor does .overlay
          }
         .listRowBackground(RoundedRectangle(cornerRadius: 25.0).fill(Color(.systemGray6)))
         .frame(height: 190)
         .padding([.leading, .trailing])
         .listStyle(PlainListStyle())
        }
      }
    }
  }
}

I've also tried putting this code UITextView.appearance().backgroundColor = .clear in the init() method and still no results. I have also tried putting an overlay over the text editor with .overlay(), and it gives the desired result, but then I can't interact with the text editor. I would go to iOS 16 and use their new text field, but this needs to work with iOS 15 so please keep that in mind.

Tank12
  • 323
  • 3
  • 12

0 Answers0