System close and prominent done buttons in SwiftUI

How do you create a toolbar item using the standard system close button or prominent done (✔️) button in SwiftUI?

In UIKit UIBarButtonItem provides .close and .done system items, and to get the tinted checkmark for done you set style = .prominent.

Answered by BabyJ in 847139022

SwiftUI provides a similar set of features. To get the standard system buttons, a new Button initialiser allows you to create a button with a role and action, and provides a default label for you.

You can get the system button for any of these button roles: .cancel, .destructive, .close, .confirm. And you can use them like this:

// Standard close button
Button(role: .close) {
    ...
}

// Standard done button (prominent in toolbar)
Button(role: .confirm) {
    ...
}

// Prominent tinted button
.buttonStyle(.borderedProminent)
Accepted Answer

SwiftUI provides a similar set of features. To get the standard system buttons, a new Button initialiser allows you to create a button with a role and action, and provides a default label for you.

You can get the system button for any of these button roles: .cancel, .destructive, .close, .confirm. And you can use them like this:

// Standard close button
Button(role: .close) {
    ...
}

// Standard done button (prominent in toolbar)
Button(role: .confirm) {
    ...
}

// Prominent tinted button
.buttonStyle(.borderedProminent)
System close and prominent done buttons in SwiftUI
 
 
Q