Instance Method

offset(x:y:)

Offsets the view by the specified horizontal and vertical distances.

Declaration

func offset(x: CGFloat = 0, y: CGFloat = 0) -> some View

Parameters

x

The horizontal distance to offset this view.

y

The vertical distance to offset this view.

Return Value

A view that offsets this view by x and y.

Discussion

The original dimensions of the view are considered to be unchanged by offsetting the contents. For example, the gray border drawn by this view surrounds the original position of the text:

Text("Hello world!")
.font(.title)
.offset(x: 50, y: 10)
.border(Color.gray)

See Also

Setting the Position of a View

func position(CGPoint) -> View

Fixes the center of the view at the specified point in its parent’s coordinate space.

func position(x: CGFloat, y: CGFloat) -> View

Fixes the center of the view at the specified coordinates in its parent’s coordinate space.

func offset(CGSize) -> View

Offsets the view by the horizontal and vertical distances in the given size.

func edgesIgnoringSafeArea(Edge.Set) -> View

Extends the view out of the safe area on the specified edges.

func coordinateSpace<T>(name: T) -> View

Assigns a name to this view’s coordinate space to which descendants of this view can refer.