Contents

overlayPreferenceValue(_:alignment:_:)

Reads the specified preference value from the view, using it to produce a second view that is applied as an overlay to the original view.

Declaration

nonisolated func overlayPreferenceValue<K, V>(_ key: K.Type, alignment: Alignment = .center, @ViewBuilder _ transform: @escaping (K.Value) -> V) -> some View where K : PreferenceKey, V : View

Parameters

  • key:

    The preference key type whose value is to be read.

  • alignment:

    An optional alignment to use when positioning the overlay view relative to the original view.

  • transform:

    A function that produces the overlay view from the preference value read from the original view.

Return Value

A view that layers a second view in front of the view.

Discussion

The values of the preference key from both views are combined and made visible to the parent view.

See Also

Generating backgrounds and overlays from preferences