跳转至
Structure

EdgeInsets

The inset distances for the sides of a rectangle.

Declaration

@frozen struct EdgeInsets : Equatable

Overview

Use this structure for 3 different modifiers:

  1. listRowInsets(_:)
  2. View/padding(_:)
  3. resizable(capInsets:resizingMode:)

This structure represents a point value in all 4 rectangular directions, top, leading, bottom, trailing.

In the following example, padding is added to a rectangle using edge insets:

struct PaddedRectangleView: View {
    let insets = EdgeInsets(top: 20, leading: 5, bottom: 30, trailing: 10)

    var body: some View {
        Rectangle()
            .padding(insets)
    }
}
A view containing a default rectangle with padding insets, a static variable defined by EdgeInsets; the black rectangle fills up most of the frame up until the edges, where a gap remains due to the insets.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Alias

AnimatableData The type defining the data to animate.


Type Method

==(a:b:) Returns a Boolean value indicating whether two values are equal.


Initializer

init() Creates a new EdgeInsets with zero insets on all edges.

init(_:) Create edge insets from the equivalent NSDirectionalEdgeInsets.

init(top:leading:bottom:trailing:) Creates a new EdgeInsets from inset parameters.


Instance Property

animatableData The data to animate.

bottom How far inset the rectangle is from the bottom edge.

leading How far inset the rectangle is from the leading edge.

top How far inset the rectangle is from the top edge.

trailing How far inset the rectangle is from the trailing edge.