Adds a border to the view with the specified style and width.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Swift
UI
Declaration
func border<S>(_ content: S, width: CGFloat = 1) -> some View where S : Shape Style
Parameters
content
The border style.
width
The thickness of the border.
Return Value
A view that adds a border with the specified style and width to this view.
Discussion
By default, the border appears inside the bounds of this view. In this example, the four-point border covers the text:
Text("Artichokes")
.font(.title)
.border(Color.green, width: 4)
To place a border around the outside of this view, apply padding of the same width before adding the border:
Text("Artichokes")
.font(.title)
.padding(4)
.border(Color.green, width: 4)