UserInterfaceStyleOverridingElement

public struct UserInterfaceStyleOverridingElement : Element

An element that allows overriding the user interface style (light/dark mode) for its wrapped content.

Use this element to force a specific appearance for a portion of your UI, regardless of the system-wide settings. This can be useful when you need to ensure certain UI elements maintain a consistent appearance across different user interface styles.

Example:

let content = Label(text: "Hello, World!")
let forcedLightMode = UserInterfaceStyleOverridingElement(
    userInterfaceStyle: .light,
    wrapping: content
)
  • The element being wrapped with the overridden interface style.

    Declaration

    Swift

    public var wrappedElement: Element
  • The user interface style to apply to the wrapped content. This can be .light, .dark, or .unspecified.

    Declaration

    Swift

    public var userInterfaceStyle: UIUserInterfaceStyle
  • Creates a new element that overrides the user interface style for its wrapped content.

    Declaration

    Swift

    public init(
        userInterfaceStyle: UIUserInterfaceStyle,
        wrapping content: () -> (Element)
    )

    Parameters

    userInterfaceStyle

    The desired interface style to apply (.light, .dark, or .unspecified).

    wrapping

    The content whose interface style should be overridden.

  • Declaration

    Swift

    public var content: ElementContent { get }
  • Declaration

    Swift

    public func backingViewDescription(with context: ViewDescriptionContext) -> ViewDescription?