Contents

border(_:width:)

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

Declaration

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

Parameters

  • content:

    A value that conforms to the Shapestyle protocol, like a Color or Hierarchicalshapestyle, that SwiftUI uses to fill the border.

  • width:

    The thickness of the border. The default is 1 pixel.

Mentioned in

Return Value

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

Discussion

Use this modifier to draw a border of a specified width around the view’s frame. By default, the border appears inside the bounds of this view. For example, you can add a four-point wide border covers the text:

Text("Purple border inside the view bounds.")
    .border(Color.purple, width: 4)

[Image]

To place a border around the outside of this view, apply padding of the same width before adding the border:

Text("Purple border outside the view bounds.")
    .padding(4)
    .border(Color.purple, width: 4)

[Image]

See Also

Styling content