Generic Instance Method

border(_:width:)

Adds a border to this view with the specified style and width.

Declaration

func border<S>(_ content: S, width: CGFloat = 1) -> some View where S : ShapeStyle

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)

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software