iosswiftswiftuibackground-color

Background color not change TextEditor view


//.........some other views........

       ZStack(alignment: .leading ) {
            
            Color.black.ignoresSafeArea()
            TextEditor(text: $mytext)
                .background(Color.orange)
                .padding()
                .foregroundColor(Color.gray)
                .frame(width: 362, height: 400)
            

        }

Background color remains Color.white for all cases i applied so what's wrong here? Thank you.


Solution

  • We need to clear default background color via appearance

        init() {
            UITextView.appearance().backgroundColor = .clear
        }
    

    and then background modifier works in any mode

        TextEditor(text: $mytext)
            .background(Color.orange)
    

    Tested with Xcode 13.4 / iOS 15.5

    demo