Structure

EditButton

A button that toggles the edit mode for the current edit scope.

Declaration

struct EditButton

Topics

Creating an Edit Button

Implementing a Custom View

Setting the Size of a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions this view within an invisible frame with the specified size.

func fixedSize() -> View

Fixes this view at its ideal size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes this view at its ideal size in the specified dimensions.

Specifying the Relative Size of a View

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to this child.

Setting the Position of a View

func position(CGPoint) -> View

Fixes the center of this view at the specified point in its parent’s coordinate space.

func position(x: CGFloat, y: CGFloat) -> View

Fixes the center of this view at the specified coordinates in its parent’s coordinate space.

func offset(CGSize) -> View

Offsets this view by the horizontal and vertical distances in the given size.

func offset(x: CGFloat, y: CGFloat) -> View

Offsets this view by the specified horizontal and vertical distances.

func edgesIgnoringSafeArea(Edge.Set) -> View

Extends the view out of the safe area on the specified edges.

Aligning Views

func alignmentGuide(HorizontalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

func alignmentGuide(VerticalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

Adjusting the Padding of a View

func padding(CGFloat) -> View

Pads this view along all edge insets by the amount you specify.

func padding(EdgeInsets) -> View

Pads this view using the edge insets you specify.

func padding(Edge.Set, CGFloat?) -> View

Pads this view using the edge insets you specify.

Setting the Foreground or Background of a View

Setting the Border of a View

func border<S>(S, width: CGFloat) -> View

Adds a border to this view with the specified style and width.

Masking and Clipping Views

func clipped(antialiased: Bool) -> View

Clips this view to its bounding rectangular frame.

func clipShape<S>(S, style: FillStyle) -> View

Sets a clipping shape for this view.

func cornerRadius(CGFloat, antialiased: Bool) -> View

Clips this view to its bounding frame, with the specified corner radius.

Scaling Views

Adjusting Text in a View

func font(Font?) -> View

Sets the default font for text in this view.

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in this view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in this view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text in this view scales down to fit in the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

func allowsTightening(Bool) -> View

Sets whether text in this view can compress the space between characters when necessary to fit text in a line.

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether this view flips its contents horizontally when the layout direction is right-to-left.

Adding Animations to a View

func animation(Animation?) -> View

Applies the given animation to all animatable values within this view.

func animation<V>(Animation?, value: V) -> View

Applies the given animation to this view, whenever the specified value changes.

func transition(AnyTransition) -> View

Associates a transition with self.

Handling View Events

func onAppear(perform: (() -> Void)?) -> View

Adds an action to perform when this view appears.

func onDisappear(perform: (() -> Void)?) -> View

Adds an action to perform when this view disappears.

Adopting View Color Schemes

func colorScheme(ColorScheme) -> View

Sets this view’s color scheme.

func accentColor(Color?) -> View

Sets the accent color for this view and the views it contains.

Applying Blurs and Shadows to a View

Applying Graphical Effects to a View

func opacity(Double) -> View

Sets the transparency of this view.

func brightness(Double) -> View

Brightens this view by the specified amount.

func contrast(Double) -> View

Sets the contrast and separation between similar colors in this view.

func colorInvert() -> View

Inverts the colors in this view.

func colorMultiply(Color) -> View

Adds a color multiplication effect to this view.

func blendMode(BlendMode) -> View

Sets the blend mode for compositing this view with overlapping views.

func compositingGroup() -> View

Wraps this view in a compositing group.

func drawingGroup(opaque: Bool, colorMode: ColorRenderingMode) -> View

Composites this view’s contents into an offscreen image before final display.

func saturation(Double) -> View

Adjusts the color saturation of this view.

func grayscale(Double) -> View

Adds a grayscale effect to this view.

func hueRotation(Angle) -> View

Applies a hue rotation effect to this view.

func luminanceToAlpha() -> View

Adds a luminance to alpha effect to this view.

Configuring a List View

func listRowInsets(EdgeInsets?) -> View

Sets the inset to be applied to self in a List.

func listRowBackground<V>(V?) -> View

Sets the view to be placed behind self when placed in a List

Hiding and Disabling Views

func hidden() -> View

Hides this view.

func disabled(Bool) -> View

Adds a condition that controls whether users can interact with this view.

func deleteDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be deleted.

func moveDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be moved.

Responding to View Preferences

func onPreferenceChange<K>(K.Type, perform: (K.Value) -> Void) -> View

Adds an action to perform when the specified preference key’s value changes.

func backgroundPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as as the background to self.

func overlayPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as an overlay on self.

Setting the Environment Values of a View

func environment<V>(WritableKeyPath<EnvironmentValues, V>, V) -> View

Returns a view wrapping self that sets a value for an environment keyPath.

func transformEnvironment<V>(WritableKeyPath<EnvironmentValues, V>, transform: (inout V) -> Void) -> View

Returns a view wrapping self that transforms the value of the environment key described by keyPath by applying a transform function.

Configuring a View for Hit Testing

func contentShape<S>(S, eoFill: Bool) -> View

Returns a new view that defines the content shape for hit-testing self as shape. eoFill defines whether the shape is interpreted using the even-odd winding number rule or not.

Configuring View Previews

func previewDevice(PreviewDevice?) -> View

Overrides the device for a preview.

func previewDisplayName(String?) -> View

Provides a user visible name shown in the editor.

func previewLayout(PreviewLayout) -> View

Overrides the size of the container for the preview.

Inspecting Views

Relationships

Conforms To

See Also

Buttons

struct Button

A control that performs an action when triggered.

struct NavigationLink

A button that triggers a navigation presentation when pressed.

struct MenuButton

A button that displays a menu containing a list of choices when pressed.

struct PasteButton

A system button that triggers reading data from the pasteboard.