Nighthawk
Nighthawk

Reputation: 982

How can I make a text editor with some style in SwiftUI?

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

Upvotes: 5

Views: 6836

Answers (2)

From iOS 16 you can use

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

Upvotes: 4

Harshil Patel
Harshil Patel

Reputation: 1474

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
        }
    }
}

Upvotes: 2

Related Questions