SwiftUI on Mac - How do I designate a button as being the primary?

前端 未结 3 473
暖寄归人
暖寄归人 2021-01-02 11:44

In AppKit I would do this by assigning its key equivalent to be ↩ or making its cell the window\'s default. However, neither of these seems possible in SwiftUI, so h

3条回答
  •  天涯浪人
    2021-01-02 12:23

    macOS 10.16 / iOS 14:

    As of Xcode 12 beta, new methods are exposed on Button() allowing assignment of keyEquivalent (either by enum case or explicit key and modifiers).

    Setting as default:

    Button( ... )
        .keyboardShortcut(.defaultAction)
    

    Setting as cancel:

    Button( ... )
        .keyboardShortcut(.cancelAction)
    

提交回复
热议问题