scenePadding
Adds padding to the specified edges of this view using an amount that's appropriate for the current scene.
Overloads
2 ways to call compose().scenePadding(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().scenePadding(edges?: SwiftUI.EdgeSet)nonisolated func scenePadding(_ edges: Edge.Set = .all) -> some ViewParameters
edgesSwiftUI.EdgeSetThe set of edges along which to pad this view.
Return value
A view that's padded on specified edges by a scene-appropriate amount.
Discussion
Use this modifier to add a scene-appropriate amount of padding to a
view. Specify either a single edge value from Edge.Set, or an
doc://com.apple.documentation/documentation/Swift/OptionSet that
describes the edges to pad.
In macOS, use scene padding to produce the recommended spacing around
the root view of a window. In watchOS, use scene padding to align
elements of your user interface with top level elements, like the title
of a navigation view. For example, compare the effects of different
kinds of padding on text views presented inside a NavigationView
in watchOS:
VStack(alignment: .leading, spacing: 10) {
Text("Scene padding")
.scenePadding(.horizontal)
.border(.red) // Border added for reference.
Text("Regular padding")
.padding(.horizontal)
.border(.green)
Text("Text with no padding")
.border(.blue)
Button("Button") { }
}
.navigationTitle("Hello World")The text with scene padding automatically aligns with the title, unlike the text that uses the default padding or the text without padding:
Scene padding in watchOS also ensures that your content avoids the
curved edges of a device like Apple Watch Series 7.
In other platforms, scene padding produces the same default padding that
you get from the View.padding(_:_:) modifier.
view in watchOS, even if you specify those edges as part of the input.
For example, if you specify Edge.Set.vertical instead of
Edge.Set.horizontal in the example above, the modifier would have
no effect in watchOS. It does, however, apply to all the edges that you
specify in other platforms.
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.