跳转至
Structure

VerticalAlignment

An alignment position along the horizontal axis.

Declaration

@frozen struct VerticalAlignment : Equatable

Overview

Use this structure in the initializers of 3 structures:

See those pages for more on how to construct them.

This structure is also used in the alignmentGuide(_:computeValue:) view modifier. See that page for more on adding alignment guides to views.

There are 5 possible vertical alignments:

  1. top
  2. center
  3. bottom
  4. firstTextBaseline
  5. lastTextBaseline

See the example below.

struct VerticallyAlignedView: View {
    var body: some View {
        HStack(alignment: VerticalAlignment.top) { //Try changing this value
            Rectangle()
                .fill(Color.red)
                .frame(width: 50, height: 2)

            VStack {
                Text("Align 1")
                Text("Align 2")
            }
            .font(.largeTitle)
        }
    }
}
A view containing an HStack with a thin red rectangle with top vertical alignment and a VStack with two largeTitle font text views aligned directly below and to the right of the red rectangle.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init(_:) Creates an instance with the given identifier.


Type Method

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


Type Property

bottom A guide marking the bottom edge of the view.

center A guide marking the vertical center of the view.

firstTextBaseline A guide marking the topmost text baseline view.

lastTextBaseline A guide marking the bottom-most text baseline in a view.

top A guide marking the top edge of the view.