TechnologiesSwiftUI

PlainTextEditorStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A text editor style with no decoration.

How it works

PlainTextEditorStyle is the text-editor style that renders a TextEditor as unadorned, plain text — no automatic rich-text affordances, just the characters the user types. It conforms to TextEditorStyle, the protocol SwiftUI uses to describe how an editor presents and edits its content, and you almost never name the type directly: you select it through the .plain static accessor on the textEditorStyle(_:) modifier. Reach for it when you want a lightweight, code-like or note-taking editing surface whose appearance you control yourself, rather than one that styles content for you.

  1. Adopt the style with textEditorStyle(.plain)

    Every TextEditor renders with an active editor style, and the textEditorStyle(_:) modifier is how you choose it. Applying .textEditorStyle(.plain) to the TextEditor(text: $notes) resolves to a PlainTextEditorStyle value and tells SwiftUI to draw the editor as flat, unstyled text.

  2. Resolve PlainTextEditorStyle through the .plain accessor

    PlainTextEditorStyle is exposed as a static member named plain on TextEditorStyle, so the leading-dot .plain in the example is shorthand for the concrete style value. You rarely write PlainTextEditorStyle() by hand — the accessor keeps the call site readable while still conforming to the TextEditorStyle protocol the modifier expects.

  3. Bind editable content with TextEditor(text:)

    The style only governs presentation; the editable text still flows through a binding. Here TextEditor(text: $notes) is driven by the @State private var notes string, and PlainTextEditorStyle leaves that text untouched — multi-line content like the newline-separated notes is shown verbatim.

  4. Control the surrounding chrome yourself

    Because the plain style adds no decoration of its own, you supply any framing or sizing through ordinary modifiers. The .frame(height: 140) and .border(Color.gray.opacity(0.4)) after the style give the otherwise bare editor its bounds and outline — the style stays focused on the text, and you own the rest.

Try it — Delete the .textEditorStyle(.plain) line and rerun to compare the bare PlainTextEditorStyle against the platform's default editor appearance.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

PlainTextEditorStyle.swift
struct PlainTextEditorStyleDemo: View {
    @State private var notes = "Meeting notes:\n- Ship the preview\n- Review PR"
    var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            Text("Notes")
                .font(.headline)
            TextEditor(text: $notes)
                .textEditorStyle(.plain)
                .frame(height: 140)
                .border(Color.gray.opacity(0.4))
        }
        .padding()
    }
}
Live preview
Notes Meeting notes:\n- Ship the preview\n- Review PR
Notes Meeting notes:\n- Ship the preview\n- Review PR
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →