skip to Main Content

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

2

Answers


  1. 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
            }
        }
    }
    
    Login or Signup to reply.
  2. From iOS 16 you can use

    TextEditor(text: $notes)
        .scrollContentBackground(.hidden)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search