Type Property 型プロパティ

keyboard

The item is placed in the keyboard section.

Declaration 宣言

static let keyboard: ToolbarItemPlacement

Discussion 議論

On iOS, keyboard items are above the software keyboard when present, or at the bottom of the screen when a hardware keyboard is attached.

On macOS, keyboard items will be placed inside the Touch Bar.

A FocusedValuecan be used to adjust the content of the keyboard bar based on the currently focused view. In the example below, the keyboard bar gains additional buttons only when the appropriate TextField is focused.


enum Field {
    case suit
    case rank
}


struct KeyboardBarDemo : View {
    @FocusedValue(\.field) var field: Field?


    var body: some View {
        HStack {
            TextField("Suit", text: $suitText)
                .focusedValue(\.field, .suit)
            TextField("Rank", text: $rankText)
                .focusedValue(\.field, .rank)
        }
        .toolbar {
            ToolbarItemGroup(placement: .keyboard) {
                if field == .suit {
                    Button("♣️", action: {})
                    Button("♥️", action: {})
                    Button("♠️", action: {})
                    Button("♦️", action: {})
                }
                DoneButton()
            }
        }
    }
}

See Also 参照

Getting Explicit Placement