View

public extension View
  • Applies the full SwiftThemeKit button style to the current view using the theme’s button system.

    This modifier is optional but recommended when you want to use the default layout, padding, background, and interactive states provided by SwiftThemeKit.

    You can also apply individual overrides such as buttonSize, buttonVariant, or buttonShape without needing to use this modifier, especially if you are using your own custom button style.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func applyThemeButtonStyle() -> some View

    Return Value

    A view with the themed button styling applied.

  • Overrides the button variant (e.g. .filled, .outline, .text) for this specific button.

    This is stored in the view environment and affects how applyThemeButtonStyle() renders the background, border, and interaction behavior.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func buttonVariant(_ variant: ButtonVariant) -> some View

    Parameters

    variant

    The desired button style variant.

    Return Value

    A view with the custom variant applied to the button context.

  • Overrides the button size (e.g. .small, .medium, .large, .fullWidth) for this button.

    The size affects height, padding, and possibly font size, based on the current theme configuration.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func buttonSize(_ size: ButtonSize) -> some View

    Parameters

    size

    The size token to apply.

    Return Value

    A view with the custom size stored in the environment.

  • Overrides the shape used for the button (e.g. .capsule, .rounded, .rectangle).

    This affects how the button is clipped and how the background and stroke are drawn.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func buttonShape(_ shape: ButtonShape) -> some View

    Parameters

    shape

    The shape token to apply to this button.

    Return Value

    A view with the shape override applied.

  • Applies a minimal, text-only button style without background, padding, or borders.

    Best for inline links or toolbar actions where no container styling is needed. Can still use theme typography tokens for consistent font sizing.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func plainTextButton(_ style: TextStyleToken = .buttonText, weight: Font.Weight? = nil) -> some View

    Parameters

    style

    The typography style to apply (default is .buttonText).

    weight

    Optional font weight override.

    Return Value

    A button with stripped-down appearance and themed text.

  • Overrides only the font style of the button’s label while preserving all other styles (padding, background, etc.).

    Useful when you want to adjust the font of a button without affecting its variant or layout.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func buttonLabelStyle(_ token: TextStyleToken, weight: Font.Weight? = nil) -> some View

    Parameters

    token

    The typography token to apply (e.g. .labelLarge, .bodyMedium).

    weight

    Optional font weight override.

    Return Value

    A view with the custom font style applied to the label.

  • Overrides the background color of the button’s label content.

    This can be used to apply a custom background color instead of the theme-defined one (e.g., for special states or brand-specific overrides).

    Declaration

    Swift

    @MainActor
    func buttonBackgroundColor(_ color: Color) -> some View

    Parameters

    color

    The color to use as the label’s background.

    Return Value

    A view with the background color applied to the button label.

  • Overrides the foreground (text/icon) color of the button’s label content.

    This affects the text/icon rendering but does not override other theme styles.

    Declaration

    Swift

    @MainActor
    func buttonForegroundColor(_ color: Color) -> some View

    Parameters

    color

    The color to use as the foreground.

    Return Value

    A view with the foreground color applied to the button label.

  • Applies the full SwiftThemeKit text field style using the theme’s configuration system.

    This modifier sets up the base layout, padding, shape, and interaction styling from the theme, using environment-provided values such as TextFieldVariant, TextFieldSize, TextFieldShape, and typography tokens.

    This is optional — you can use textFieldVariant, textFieldSize, or textFieldFont individually if you prefer to build a custom layout.

    Example:

    TextField("Email", text: $email)
      .applyThemeTextFieldStyle()
      .textFieldVariant(.outlined)
    

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func applyThemeTextFieldStyle() -> some View

    Return Value

    A view with the themed text field style applied.

  • Sets the visual variant of the text field, such as .filled, .outlined, or .underlined.

    This determines the field’s border, background, and focus styling.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func textFieldVariant(_ variant: TextFieldVariant) -> some View

    Parameters

    variant

    The desired text field variant.

    Return Value

    A view with the variant applied to the environment.

  • Overrides the size of the text field, such as .small, .medium, or .large.

    This affects internal padding, height, and default font unless overridden with textFieldFont.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func textFieldSize(_ size: TextFieldSize) -> some View

    Parameters

    size

    The desired size token.

    Return Value

    A view with the size styling applied.

  • Sets the corner shape of the text field (e.g., .rounded, .capsule, .rectangle).

    The shape is applied to the background or outline and affects how the field is clipped.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func textFieldShape(_ shape: TextFieldShape) -> some View

    Parameters

    shape

    The shape token to apply.

    Return Value

    A view with the shape applied.

  • Flags the text field as being in an error state, typically changing its color or border.

    Use this to visually indicate validation failure or incorrect input.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func isError(_ isError: Bool) -> some View

    Parameters

    isError

    A Boolean value indicating if the field is in error.

    Return Value

    A view with error styling conditionally applied.

  • Applies a specific font style to the text field label/content using the theme’s typography system.

    This only affects the font (size, weight, line height) and does not change layout or padding.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func textFieldFont(_ token: TextStyleToken, weight: Font.Weight? = nil) -> some View

    Parameters

    token

    The text style token to apply (e.g., .bodySmall, .labelLarge).

    weight

    Optional custom font weight (e.g., .medium, .semibold).

    Return Value

    A view with the font styling applied.

  • Applies a shadow to the view using a predefined ShadowToken from the current theme.

    The shadow style (color, radius, offset) is defined in the current theme.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func shadow(_ token: ShadowToken) -> some View

    Parameters

    token

    The shadow token to apply (e.g. .sm, .md, .focus).

    Return Value

    A view with the theme shadow applied.

  • Applies a themed font style from the current theme using a TextStyleToken.

    The font size, weight, and line height are defined by the token.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func font(_ token: TextStyleToken, weight: Font.Weight? = nil) -> some View

    Parameters

    token

    The typography style to use (e.g. .headlineMedium, .labelSmall).

    weight

    Optional override for font weight (e.g., .semibold, .regular).

    Return Value

    A view with the themed font applied.

  • Applies a themed foreground color (text, icon, etc.) using a ColorToken.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func foregroundColor(_ token: ColorToken) -> some View

    Parameters

    token

    The color token to apply (e.g. .primary, .onSurface).

    Return Value

    A view with the specified foreground color.

  • Applies a background fill color using a theme-defined ColorToken.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func backgroundColor(_ token: ColorToken) -> some View

    Parameters

    token

    The color token to apply (e.g. .surface, .primaryContainer).

    Return Value

    A view with the background color applied.

  • Applies a background fill color using a theme-defined ColorToken, ignoring safe area on specified edges.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func backgroundColor(_ token: ColorToken, edgesIgnoringSafeArea: Edge.Set) -> some View

    Parameters

    token

    The color token to apply.

    edgesIgnoringSafeArea

    The edges where the safe area should be ignored.

    Return Value

    A view with the background color applied.

  • Applies a background shape with optional fill color using theme-defined tokens.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func backgroundShape(_ token: ShapeToken, color: ColorToken? = nil) -> some View

    Parameters

    token

    The shape token to apply (e.g. .sm, .md).

    color

    Optional fill color for the shape.

    Return Value

    A view with a shaped background.

  • Applies a background shape with optional fill color and safe area edge control.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func backgroundShape(_ token: ShapeToken, color: ColorToken? = nil, edgesIgnoringSafeArea: Edge.Set) -> some View

    Parameters

    token

    The shape token to apply.

    color

    Optional fill color.

    edgesIgnoringSafeArea

    The edges where safe area should be ignored.

    Return Value

    A view with the shaped background.

  • Applies padding using a SpacingToken from the theme on specified edges.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func padding(_ edges: Edge.Set = .all, _ token: SpacingToken) -> some View

    Parameters

    edges

    The edges to apply padding to (default is .all).

    token

    The spacing token to use (e.g. .sm, .lg).

    Return Value

    A view with themed padding.

  • Applies uniform padding using a SpacingToken from the theme.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func padding(_ token: SpacingToken) -> some View

    Parameters

    token

    The spacing token to use.

    Return Value

    A view with themed padding.

  • Applies a corner radius using a RadiusToken from the current theme.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func cornerRadius(_ token: RadiusToken) -> some View

    Parameters

    token

    The radius token to apply (e.g. .sm, .pill, .circle).

    Return Value

    A view with rounded corners.

  • Clips the view to a rounded rectangle using a RadiusToken and optional style.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func clipRadius(_ token: RadiusToken, style: RoundedCornerStyle = .circular) -> some View

    Parameters

    token

    The radius token to use.

    style

    The corner style, either .circular or .continuous.

    Return Value

    A clipped view.

  • Applies a themed border stroke using stroke width, corner radius, and color from the theme.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func stroke(
      _ width: StrokeToken,
      radius: RadiusToken = .md,
      color: ColorToken = .primary
    ) -> some View

    Parameters

    width

    The stroke width from the theme.

    radius

    The corner radius from the theme (default is .md).

    color

    The border color from the theme (default is .primary).

    Return Value

    A view with the border stroke applied.

  • Clips the view using a shape defined in the current theme.

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    func clipShape(_ token: ShapeToken) -> some View

    Parameters

    token

    A ShapeToken from the theme.

    Return Value

    A view clipped to the given shape.

  • Sets a navigation title styled using the theme’s typography.

    Declaration

    Swift

    @MainActor
    func navigationTitle(
      _ title: String,
      style: TextStyleToken = .headlineLarge,
      weight: Font.Weight? = nil
    ) -> some View

    Parameters

    title

    The string to display.

    style

    Typography token (e.g. .titleLarge).

    weight

    Optional custom weight override.

    Return Value

    A view with the themed navigation title.

  • Applies layout weight and expands the view to fill available space.

    Inspired by Jetpack Compose’s weight(), useful in HStack/VStack.

    Declaration

    Swift

    @MainActor
    func weight(_ value: Double) -> some View

    Parameters

    value

    The proportional layout weight.

    Return Value

    A weighted view.

  • Expands the view to fill available width and height, aligned as specified.

    Declaration

    Swift

    @MainActor
    func fillMaxSize(alignment: Alignment = .leading) -> some View

    Parameters

    alignment

    The alignment within the space. Default is .leading.

    Return Value

    A fully expanded view.

  • Expands the view to fill the maximum width, aligned as specified.

    Declaration

    Swift

    @MainActor
    func fillMaxWidth(alignment: Alignment = .leading) -> some View

    Parameters

    alignment

    The alignment within the space. Default is .leading.

    Return Value

    A view that fills the max width.

  • Expands the view to fill the maximum height, aligned as specified.

    Declaration

    Swift

    @MainActor
    func fillMaxHeight(alignment: Alignment = .leading) -> some View

    Parameters

    alignment

    The alignment within the space. Default is .leading.

    Return Value

    A view that fills the max height.

  • Sets an exact square size for the view using the same value for width and height.

    Declaration

    Swift

    @MainActor
    func size(_ size: CGFloat, alignment: Alignment = .center) -> some View

    Parameters

    size

    The size to apply for both width and height.

    alignment

    The alignment inside the frame. Default is .center.

    Return Value

    A view with fixed size.

  • Conditionally applies a view transformation when a condition is true.

    This is useful for chaining conditional modifiers in a clean and readable way.

    Example:

    Text("Hello")
      .if(isHighlighted) { $0.foregroundColor(.red) }
    

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    public func `if`<Content>(_ condition: Bool, transform: (Self) -> Content) -> some View where Content : View

    Parameters

    condition

    A Boolean value that determines whether the transform is applied.

    transform

    A closure that takes the original view and returns a modified view.

    Return Value

    Either the original view or the transformed view if the condition is true.

  • Measures the size of the view and writes it to a bound CGSize.

    This can be used to capture layout dimensions for alignment, animation, or dynamic layout decisions.

    Example:

    @State private var size: CGSize = .zero
    
    Text("Resizable")
      .measure($size)
      .onChange(of: size) { print("New size: \($0)") }
    

    Declaration

    Swift

    @ViewBuilder
    @MainActor
    public func measure(_ size: Binding<CGSize>) -> some View

    Parameters

    size

    A binding to a CGSize value that will be updated with the view’s size.