4

How can I make a text editor with some style in SwiftUI? It seems that there a text editor can not be as customizable as the text field.

How could I achieve a result like this (here the users text is white)?

My issue is how can I set the text color to white and set the background color in a text editor.

enter image description here

Nighthawk
  • 772
  • 11
  • 21

2 Answers2

3
struct ContentView: View {
    init() {
        UITextView.appearance().backgroundColor = .clear // First, remove the UITextView's backgroundColor.
    }
    @State private var input = ""
    var body: some View {
        ZStack {
            Color.blue.edgesIgnoringSafeArea(.all)
            TextEditor(text: $input)
                .font(.body)
                .foregroundColor(.white) // Text color
                .background(Color.blue) // TextEditor's Background Color
        }
    }
}
Harshil Patel
  • 1,318
  • 1
  • 7
  • 26
0

From iOS 16 you can use

TextEditor(text: $notes)
    .scrollContentBackground(.hidden)