Generic Instance Method

border(_:width:cornerRadius:)

Adds a border to this view with the given style, width, and corner radius.

Declaration

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

Parameters

content

The border style.

width

The thickness of the border.

cornerRadius

The corner radius of the border.

Return Value

A view that adds a border with the specified style, width, and corner radius to this view.

Discussion

The border appears inside the bounds of this view, and doesn’t hide the visible area that extends beyond the border’s corners:

Image("artichokes")
.border(Color.black, width: 10, cornerRadius: 20)

To hide the visible area beyond the border’s corners, you can also apply a corner radius to the view itself:

Image("artichokes")
.border(Color.black, width: 10, cornerRadius: 20)
.cornerRadius(20)

See Also

Setting the Border of a View

func border<S>(S, width: CGFloat) -> View

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

Beta

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