Overloads
3 ways to call compose().padding(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().padding(
edges?: SwiftUI.EdgeSet,
length?: number | null
)nonisolated func padding(
_ edges: Edge.Set = .all,
_ length: CGFloat? = nil
) -> some ViewParameters
edgesSwiftUI.EdgeSetThe set of edges to pad for this view. The default is
Edge.Set.all.lengthnumber | nullAn amount, given in points, to pad this view on the specified edges. If you set the value to
nil, SwiftUI uses a platform-specific default amount. The default value of this parameter isnil.
Return value
A view that's padded by the specified amount on the specified edges.
Discussion
Use this modifier to add a specified amount of padding to one or more
edges of the view. Indicate the edges to pad by naming either a single
value from Edge.Set, or by specifying an
doc://com.apple.documentation/documentation/Swift/OptionSet
that contains edge values:
VStack {
Text("Text padded by 20 points on the bottom and trailing edges.")
.padding([.bottom, .trailing], 20)
.border(.gray)
Text("Unpadded text for comparison.")
.border(.yellow)
}The order in which you apply modifiers matters. The example above applies the padding before applying the border to ensure that the border encompasses the padded region:
You can omit either or both of the parameters. If you omit the length,
SwiftUI uses a default amount of padding. If you
omit the edges, SwiftUI applies the padding to all edges. Omit both
to add a default padding all the way around a view. SwiftUI chooses a
default amount of padding that's appropriate for the platform and
the presentation context.
VStack {
Text("Text with default padding.")
.padding()
.border(.gray)
Text("Unpadded text for comparison.")
.border(.yellow)
}The example above looks like this in iOS under typical conditions:
To control the amount of padding independently for each edge, use
View.padding(_:)-6pgqq. To pad all outside edges of a view by a
specified amount, use View.padding(_:)-68shk.
See also
More in Layout.
- alignmentGuideSets the view's vertical alignment.
- aspectRatioConstrains this view's dimensions to the specified aspect ratio.
- containerCornerOffsetAdjusts the view's layout to avoid the container view's corner insets for the specified edges.
- containerRelativeFramePositions this view within an invisible frame with a size relative to the nearest container.
- controlSizeSets the size for controls within this view.
- defaultScrollAnchorAssociates an anchor to control which part of the scroll view's content should be rendered by default.
- dynamicTypeSizeSets the Dynamic Type size within the view to the given value.
- fixedSizeFixes this view at its ideal size.
- flipsForRightToLeftLayoutDirectionSets whether this view mirrors its contents horizontally when the layout direction is right-to-left.
- framePositions this view within an invisible frame.
- geometryGroupIsolates the geometry (e.g. position and size) of the view from its parent view.
- gridCellAnchorSpecifies a custom alignment anchor for a view that acts as a grid cell.