Official .bordered
modifier support in iOS 15+
Button
s now have baked in border styling support using the .buttonStyle(.bordered)
modifier. I would suggest using the corner radius Apple provides for these buttons for the best platform-specific styling. We can change the color to be consistent with the system styles for buttons and tint the background as well as text using the .tint
modifier:
Button("Add") { ... }
.buttonStyle(.bordered)
.tint(.green)

You can make the tint color more prominent (bolder) using .borderedProminent
and control the size using .controlSize
:
Button("food") { ... }
.tint(.red)
.controlSize(.small) // .large, .medium or .small
.buttonStyle(.borderedProminent)

You can also use this modifier on parent View
s of Button
s and toggle lighter color schemes using .accentColor
in child Button
s:
ScrollView {
LazyVStack {
Button("Test Button 1") { ... }
.buttonStyle(.borderedProminent)
.keyboardShortcut(.defaultAction) // Tapping `Return` key actions this button
Button("Test Button 2") { ... }
.tint(.accentColor)
}
}
.buttonStyle(.bordered)
.controlSize(.large)

Advice
Apple for some reason doesn't like single-line bordered buttons which is why the .border()
modifier was deprecated in Xcode 12. With this change, I suggest developers avoid creating single-line bordered buttons because they now are not preferred in Apple's Human Interface Guidelines. Using prominent buttons everywhere also violates HIG.
Extra NOTE: Apple's .bordered
style provides the standard platform style across device types. In addition, the Button
responds to Dark Mode dynamically and scales its size with Dynamic Type (native accessibility support).