Generic Structure

VStack

A view that arranges its children in a vertical line.

Declaration

struct VStack<Content> where Content : View

Topics

Creating a Stack

init(alignment: HorizontalAlignment, spacing: Length?, content: () -> Content)

Creates an instance with the given spacing and Y axis alignment.

struct HorizontalAlignment

An alignment position along the horizontal axis

enum HAlignment

Aligns the child view within its bounds given anchor types

Specifying the Relative Size of a View

func relativeSize(width: Length, height: Length) -> _ModifiedContent<VStack<Content>, _RelativeLayoutTraitsLayout>

Sets the size of this view to the specified proportion of its parent’s width and height.

func relativeWidth(Length) -> _ModifiedContent<VStack<Content>, _RelativeLayoutTraitsLayout>

Sets the width of this view to the specified proportion of its parent’s width.

func relativeHeight(Length) -> _ModifiedContent<VStack<Content>, _RelativeLayoutTraitsLayout>

Sets the height of this view to the specified proportion of its parent’s height.

func layoutPriority(Double) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Double>>

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

Setting the Position of a View

func position(CGPoint) -> _ModifiedContent<VStack<Content>, _PositionLayout>

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

func position(x: Length, y: Length) -> _ModifiedContent<VStack<Content>, _PositionLayout>

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

func offset(CGSize) -> _ModifiedContent<VStack<Content>, _OffsetEffect>

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

func offset(x: Length, y: Length) -> _ModifiedContent<VStack<Content>, _OffsetEffect>

Offsets this view by the specified horizontal and vertical distances.

Aligning Views

func alignmentGuide(HorizontalAlignment, computeValue: (ViewDimensions) -> Length) -> _ModifiedContent<VStack<Content>, _AlignmentWritingModifier>

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) -> Length) -> _ModifiedContent<VStack<Content>, _AlignmentWritingModifier>

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(Length) -> _ModifiedContent<VStack<Content>, _PaddingLayout>

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

Adjusting Text in a View

func lineLimit(Int?) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyWritingModifier<Int?>>

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

func minimumScaleFactor(Length) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyWritingModifier<Length>>

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

func truncationMode(Text.TruncationMode) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyWritingModifier<Text.TruncationMode>>

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

func allowsTightening(Bool) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyWritingModifier<Bool>>

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

func flipsForRightToLeftLayoutDirection(Bool) -> _ModifiedContent<VStack<Content>, _FlipForRTLEffect>

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

Adding Animations to a View

Handling View Taps and Gestures

func itemProvider(Optional<() -> NSItemProvider?>) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Optional<() -> NSItemProvider?>>>

Provides a closure that vends the drag representation to be used for a particular DynamicContent.

func transaction((inout Transaction) -> Void) -> _ModifiedContent<VStack<Content>, _TransactionModifier>

Applies the given transaction mutation function to all transactions used within the view.

Handling View Events

Handling View Hover and Focus

func onHover(perform: (Bool) -> Void) -> _ModifiedContent<VStack<Content>, _HoverRegionModifier>

Adds an action to perform when the user moves the pointer over or away from this view’s frame.

func focusable(Bool, onFocusChange: (Bool) -> Void) -> _ModifiedContent<VStack<Content>, _FocusableModifier>

Sets whether this view is focusable and, if so, adds an action to perform when the view comes into focus.

Supporting Drag and Drop in Views

func onDrag(() -> NSItemProvider) -> _ModifiedContent<VStack<Content>, _DraggingModifier>

Activates this view as the source of a drag and drop operation.

func onDrop(of: [String], delegate: DropDelegate) -> _ModifiedContent<VStack<Content>, _DropModifier>

Defines the destination for a drag and drop operation with the same size and position as this view, with behavior controlled by the given delegate.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider], CGPoint) -> Bool) -> _ModifiedContent<VStack<Content>, _DropModifier>

Defines the destination for a drag and drop operation with the same size and position as this view, handling dropped content and the drop location with the given closure.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider]) -> Bool) -> _ModifiedContent<VStack<Content>, _DropModifier>

Defines the destination for a drag and drop operation, using the same size and position as this view, handling dropped content with the given closure.

Applying Graphical Effects to a View

func contrast(Double) -> _ModifiedContent<VStack<Content>, _ContrastEffect>

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

func blendMode(BlendMode) -> _ModifiedContent<VStack<Content>, _BlendModeEffect>

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

Configuring a List View

Configuring Navigation and Tab Bar Item Views

Configuring Touch Bar Views

func touchBar<Content>(TouchBar<Content>) -> _ModifiedContent<VStack<Content>, _TouchBarModifier<Content>>

Sets the TouchBar and its content to be shown in the Touch Bar when applicable

func touchBarItemPrincipal(Bool) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Bool>>

Principal views have special significance to this TouchBar. Currently, that item will be placed in the center of the row.

func touchBarCustomizationLabel(Text) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Text>>

The user-visible String identifying the view’s functionality. Visible during user customization.

Hiding and Disabling Views

func disabled(Bool) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyTransformModifier<Bool>>

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

func deleteDisabled(Bool) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Bool>>

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

func moveDisabled(Bool) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<Bool>>

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

Responding to View Preferences

func backgroundPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> _DelayedPreferenceView<Key, _ModifiedContent<VStack<Content>, _BackgroundModifier<_PreferenceReadingView<Key, T>>>>

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) -> _DelayedPreferenceView<Key, _ModifiedContent<VStack<Content>, _OverlayModifier<_PreferenceReadingView<Key, T>>>>

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 transformEnvironment<V>(WritableKeyPath<EnvironmentValues, V>, transform: (inout V) -> Void) -> _ModifiedContent<VStack<Content>, _EnvironmentKeyTransformModifier<V>>

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) -> _ModifiedContent<VStack<Content>, _ContentShapeModifier<S>>

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.

Inspecting Views

func id<ID>(ID) -> IDView<VStack<Content>, ID>

Returns a uniquely identified view that can be inserted or removed.

Implementing View Modifiers

Type Aliases

typealias VStack.Modified

The type resulting from applying a view modifier T.

Instance Methods

func tag<V>(V) -> _ModifiedContent<VStack<Content>, _TraitWritingModifier<_ViewTag<V>>>

Sets the tag of the view, used for selecting from a list of View options.

See Also

Stacks

struct HStack

A view that arranges its children in a horizontal line.

Beta
struct ZStack

A view that overlays its children, aligning them in both axes.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software