border

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

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+border(_:width:) in SwiftUI

Declaration

React
compose().border(
  content: SwiftUI.ShapeStyle,
  options?: {
    width?: number;
  }
)
Swift
nonisolated func border<S>(
    _ content: S,
    width: CGFloat = 1
) -> some View
where S : ShapeStyle

Parameters

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)

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)

See also

More in Appearance.