position

Positions the center of this view at the specified point in its parent's coordinate space.

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

Overloads

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

React
compose().position(position: CGPoint)
Swift
nonisolated func position(_ position: CGPoint) -> some View

Parameters

  • position*CGPoint

    The point at which to place the center of this view.

Return value

A view that fixes the center of this view at position.

Discussion

Use the position(_:) modifier to place the center of a view at a specific coordinate in the parent view using a doc://com.apple.documentation/documentation/CoreFoundation/CGPoint to specify the x and y offset.

Text("Position by passing a CGPoint()")
    .position(CGPoint(x: 175, y: 100))
    .border(Color.gray)

See also

More in Layout.