Overloads
4 ways to call compose().contentMargins(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().contentMargins(
edges: SwiftUI.EdgeSet | undefined,
length: number | null,
options?: {
for?: SwiftUI.ContentMarginPlacement;
}
)nonisolated func contentMargins(
_ edges: Edge.Set = .all,
_ length: CGFloat?,
for placement: ContentMarginPlacement = .automatic
) -> some ViewParameters
edges*SwiftUI.EdgeSet | undefinedThe edges to add the margins to.
length*number | nullThe amount of margins to add.
options.forSwiftUI.ContentMarginPlacement
Discussion
Use this modifier to customize the content margins of different
kinds of views. For example, you can use this modifier to customize
the margins of scrollable views like ScrollView. In the
following example, the scroll view will automatically inset
its content by the safe area plus an additional 20 points
on the leading and trailing edge.
ScrollView(.horizontal) {
// ...
}
.contentMargins(.horizontal, 20.0)You can provide a ContentMarginPlacement to target specific
parts of a view to customize. For example, provide a
ContentMarginPlacement.scrollContent placement to
inset the content of a TextEditor without affecting the
insets of its scroll indicators.
TextEditor(text: $text)
.contentMargins(.horizontal, 20.0, for: .scrollContent)Similarly, you can customize the insets of scroll indicators separately from scroll content. Consider doing this when applying a custom clip shape that may clip the indicators.
ScrollView {
// ...
}
.clipShape(.rect(cornerRadius: 20.0))
.contentMargins(10.0, for: .scrollIndicators)When applying multiple contentMargins modifiers, modifiers with the same placement will override modifiers higher up in the view hierarchy.
See also
More in Other modifiers.
- idBinds a view's identity to the given proxy value.
- modifierApplies a modifier to a view and returns a new view.
- persistentSystemOverlaysSets the preferred visibility of the non-transient system views overlaying the app.
- renameActionSets the rename action in the environment to update focus state.
- tagSets the unique tag value of this view.
- typeSelectEquivalentSets an explicit type select equivalent text in a collection, such as a list or table.