offset

Offset this view by the horizontal and vertical amount specified in the offset parameter.

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+

Overloads

2 ways to call compose().offset(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().offset(offset: CGSize)
Swift
nonisolated func offset(_ offset: CGSize) -> some View

Parameters

  • offset*CGSize

    The distance to offset this view.

Return value

A view that offsets this view by offset.

Discussion

Use offset(_:) to shift the displayed contents by the amount specified in the offset parameter.

The original dimensions of the view aren't changed by offsetting the contents; in the example below the gray border drawn by this view surrounds the original position of the text:

Text("Offset by passing CGSize()")
    .border(Color.green)
    .offset(CGSize(width: 20, height: 25))
    .border(Color.gray)

See also

More in Layout.