Contents

explicitAlignment(of:in:proposal:subviews:cache:)

Returns the position of the specified horizontal alignment guide along the x axis.

Declaration

func explicitAlignment(of guide: HorizontalAlignment, in bounds: CGRect, proposal: ProposedViewSize, subviews: Self.Subviews, cache: inout Self.Cache) -> CGFloat?

Parameters

  • guide:

    The Horizontalalignment guide that the method calculates the position of.

  • bounds:

    The region that the container view’s parent allocates to the container view, specified in the parent’s coordinate space.

  • proposal:

    A proposed size for the container.

  • subviews:

    A collection of proxy instances that represent the views arranged by the container. You can use the proxies in the collection to get information about the subviews as you determine where to place the guide.

  • cache:

    Optional storage for calculated data that you can share among the methods of your custom layout container. See Makecache(subviews:) for details.

Return Value

The guide’s position relative to the bounds. Return nil to indicate that the guide doesn’t have an explicit value.

Discussion

Implement this method to return a value for the specified alignment guide of a custom layout container. The value you return affects the placement of the container as a whole, but it doesn’t affect how the container arranges subviews relative to one another.

You can use this method to put an alignment guide in a nonstandard position. For example, you can indent the container’s leading edge alignment guide by 10 points:

extension BasicVStack {
    func explicitAlignment(
        of guide: HorizontalAlignment,
        in bounds: CGRect,
        proposal: ProposedViewSize,
        subviews: Subviews,
        cache: inout ()
    ) -> CGFloat? {
        if guide == .leading {
            return bounds.minX + 10
        }
        return nil
    }
}

The above example returns nil for other guides to indicate that they don’t have an explicit value. A guide without an explicit value behaves as it would for any other view. If you don’t implement the method, the protocol’s default implementation merges the subviews’ guides.

See Also

Reporting layout container characteristics