Change background color of TextEditor in SwiftUI

前端 未结 1 787
醉话见心
醉话见心 2021-01-11 12:43

TextEditor seems to have a default white background. So the following is not working and it displayed as white instead of defined red:

相关标签:
1条回答
  • 2021-01-11 12:56

    TextEditor is backed by UITextView. So you need to get rid of the UITextView's backgroundColor first and then you can set any View to the background.

    struct ContentView: View {
        init() {
            UITextView.appearance().backgroundColor = .clear
        }
    
        var body: some View {
            TextEditor(text: .constant("Placeholder"))
                .background(Color.red)
        }
    }
    
    0 讨论(0)
提交回复
热议问题