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, orbuttonShapewithout needing to use this modifier, especially if you are using your own custom button style.Declaration
Swift
@ViewBuilder @MainActor func applyThemeButtonStyle() -> some ViewReturn 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 ViewParameters
variantThe 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 ViewParameters
sizeThe 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 ViewParameters
shapeThe 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 ViewParameters
styleThe typography style to apply (default is
.buttonText).weightOptional 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 ViewParameters
tokenThe typography token to apply (e.g.
.labelLarge,.bodyMedium).weightOptional 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 ViewParameters
colorThe 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 ViewParameters
colorThe 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, ortextFieldFontindividually if you prefer to build a custom layout.Example:
TextField("Email", text: $email) .applyThemeTextFieldStyle() .textFieldVariant(.outlined)Declaration
Swift
@ViewBuilder @MainActor func applyThemeTextFieldStyle() -> some ViewReturn 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 ViewParameters
variantThe 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 ViewParameters
sizeThe 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 ViewParameters
shapeThe 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 ViewParameters
isErrorA 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 ViewParameters
tokenThe text style token to apply (e.g.,
.bodySmall,.labelLarge).weightOptional 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
ShadowTokenfrom the current theme.The shadow style (color, radius, offset) is defined in the current theme.
Declaration
Swift
@ViewBuilder @MainActor func shadow(_ token: ShadowToken) -> some ViewParameters
tokenThe 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 ViewParameters
tokenThe typography style to use (e.g.
.headlineMedium,.labelSmall).weightOptional 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 ViewParameters
tokenThe 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 ViewParameters
tokenThe 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 ViewParameters
tokenThe color token to apply.
edgesIgnoringSafeAreaThe 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 ViewParameters
tokenThe shape token to apply (e.g.
.sm,.md).colorOptional 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 ViewParameters
tokenThe shape token to apply.
colorOptional fill color.
edgesIgnoringSafeAreaThe edges where safe area should be ignored.
Return Value
A view with the shaped background.
-
Applies padding using a
SpacingTokenfrom the theme on specified edges.Declaration
Swift
@ViewBuilder @MainActor func padding(_ edges: Edge.Set = .all, _ token: SpacingToken) -> some ViewParameters
edgesThe edges to apply padding to (default is
.all).tokenThe spacing token to use (e.g.
.sm,.lg).Return Value
A view with themed padding.
-
Applies uniform padding using a
SpacingTokenfrom the theme.Declaration
Swift
@ViewBuilder @MainActor func padding(_ token: SpacingToken) -> some ViewParameters
tokenThe spacing token to use.
Return Value
A view with themed padding.
-
Applies a corner radius using a
RadiusTokenfrom the current theme.Declaration
Swift
@ViewBuilder @MainActor func cornerRadius(_ token: RadiusToken) -> some ViewParameters
tokenThe 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
RadiusTokenand optional style.Declaration
Swift
@ViewBuilder @MainActor func clipRadius(_ token: RadiusToken, style: RoundedCornerStyle = .circular) -> some ViewParameters
tokenThe radius token to use.
styleThe corner style, either
.circularor.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 ViewParameters
widthThe stroke width from the theme.
radiusThe corner radius from the theme (default is
.md).colorThe 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 ViewParameters
tokenA
ShapeTokenfrom 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 ViewParameters
titleThe string to display.
styleTypography token (e.g.
.titleLarge).weightOptional 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 inHStack/VStack.Declaration
Swift
@MainActor func weight(_ value: Double) -> some ViewParameters
valueThe 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 ViewParameters
alignmentThe 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 ViewParameters
alignmentThe 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 ViewParameters
alignmentThe 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 ViewParameters
sizeThe size to apply for both width and height.
alignmentThe 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 : ViewParameters
conditionA Boolean value that determines whether the transform is applied.
transformA 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 ViewParameters
sizeA binding to a
CGSizevalue that will be updated with the view’s size.