Instance Method インスタンスメソッド

safeAreaInset(edge:alignment:spacing:content:)

Shows the specified content beside the modified view.

Declaration 宣言

func safeAreaInset<V>(edge: HorizontalEdge, alignment: VerticalAlignment = .center, spacing: CGFloat? = nil, content: () -> V) -> some View where V : View

Return Value 戻り値

A new view that displays content beside the modified view, making space for the content view by horizontally insetting the modified view.

Parameters パラメータ

edge

The horizontal edge of the view to inset by the width of content, to make space for content.

spacing

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

alignment

The alignment guide used to position content vertically.

content

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

Discussion 議論

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


struct ScrollableViewWithSideBar: View {
    var body: some View {
        ScrollView {
            ScrolledContent()
        }
        .safeAreaInset(edge: .leading, spacing: 0) {
            SideBarContent()
        }
    }
}