TechnologiesSwiftUI

TextInputFormattingControlPlacement struct

iOSmacOStvOSwatchOSvisionOSiOS 26.0+✓ renders

A structure defining the system text formatting controls

How it works

TextInputFormattingControlPlacement identifies *where* SwiftUI presents the rich-text formatting controls — the bold, italic, list, and alignment affordances — that accompany an editable AttributedString. When a view edits formatted text, the system can offer these controls in more than one location, and this type names each of those locations so you can address them individually. Reach for it whenever you need to control the visibility of formatting affordances for a specific placement rather than for the text editor as a whole, passing it as the target of textInputFormattingControlVisibility(_:for:).

  1. Edit formatted text that needs formatting controls

    TextInputFormattingControlPlacement only becomes relevant once a view edits an AttributedString, since plain strings carry no formatting to toggle. Here a TextEditor is bound to $text, whose @State value is an AttributedString, which is what makes the rich-text formatting controls applicable to this editor.

  2. Name a placement with the static members

    A value of TextInputFormattingControlPlacement designates one location where the controls can appear. You don't construct it directly; you select a placement through its provided members — in the example, .inline, which refers to the formatting controls shown alongside the text being edited rather than in a separate bar.

  3. Target that placement with the for: parameter

    The placement value is consumed by the textInputFormattingControlVisibility(_:for:) modifier, whose for: argument is a TextInputFormattingControlPlacement. Writing .for: .inline scopes the modifier so it governs only the inline controls, leaving any other placement to its default behavior.

  4. Pair it with a visibility to show or hide that location

    TextInputFormattingControlPlacement says *which* controls; the accompanying Visibility says *whether* they appear. Combined as .textInputFormattingControlVisibility(.visible, for: .inline), the modifier forces the inline formatting controls to be shown for this TextEditor.

Try it — Change .visible to .hidden in .textInputFormattingControlVisibility(.visible, for: .inline) and watch the inline formatting controls disappear while the same .inline placement keeps the modifier scoped to exactly that location.

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.

TextInputFormattingControlPlacement.swift
struct TextInputFormattingControlPlacementDemo: View {
    @State private var text = AttributedString("Edit this rich text…")

    var body: some View {
        TextEditor(text: $text)
            .frame(height: 160)
            .border(.secondary)
            .textInputFormattingControlVisibility(.visible, for: .inline)
            .padding()
    }
}
Live preview
Edit this rich text…
Edit this rich text…
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →