safeAreaInset

Shows the specified content above or below the modified view.

View ModifieriOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+

Overloads

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

React
compose().safeAreaInset({
  edge: SwiftUI.VerticalEdge,
  alignment?: SwiftUI.HorizontalAlignment,
  spacing?: number | null,
  content: ReactNode,
})
Swift
nonisolated func safeAreaInset<V>(
    edge: VerticalEdge,
    alignment: HorizontalAlignment = .center,
    spacing: CGFloat? = nil,
    @ContentBuilder content: () -> V
) -> some View
where V : View

Parameters

  • The vertical edge of the view to inset by the height of content, to make space for content.

  • The alignment guide used to position content horizontally.

  • options.spacingnumber | null

    Extra distance placed between the two views, or nil to use the default amount of spacing.

  • options.content*ReactNode

    A content builder function providing the view to display in the inset space of the modified view.

Return value

A new view that displays content above or below the modified view, making space for the content view by vertically insetting the modified view, adjusting the safe area of the result to match.

Discussion

The content view is anchored to the specified vertical edge in the parent view, aligning its horizontal axis to the specified alignment guide. The modified view is inset by the height of content, from edge, with its safe area increased by the same amount.

struct ScrollableViewWithBottomBar: View {
    var body: some View {
        ScrollView {
            ScrolledContent()
        }
        .safeAreaInset(edge: .bottom, spacing: 0) {
            BottomBarContent()
        }
    }
}

See also

More in Layout.