Checkbox
@MainActor
public struct Checkbox : View
A custom themed checkbox component that adapts to the current Theme.
Checkbox supports both text labels and custom views, as well as configurable shape and label alignment.
It is fully accessible and updates the bound isChecked state when toggled.
Example:
Checkbox(isChecked: $isOn, label: "Subscribe to newsletter")
You can also provide a custom view as a label:
Checkbox(isChecked: $isOn) {
HStack {
Image(systemName: "bell")
Text("Notify me")
}
}
-
Initializes a standalone checkbox without a label.
Declaration
Swift
@MainActor public init(isChecked: Binding<Bool>)Parameters
isCheckedA binding to the checkbox state.
-
Initializes a checkbox with a simple string label.
Declaration
Swift
@MainActor public init(isChecked: Binding<Bool>, label: String, labelSpacing: SpacingToken = .sm, labelPosition: HorizontalPosition = .trailing)Parameters
isCheckedA binding to the checkbox state.
labelThe text to display next to the checkbox.
labelPositionPosition of the label relative to the checkbox (defaults to
.trailing). -
Initializes a checkbox with a fully custom view label.
Declaration
Swift
@MainActor public init<Label: View>(isChecked: Binding<Bool>, labelSpacing: SpacingToken = .sm, labelPosition: HorizontalPosition = .trailing, @ViewBuilder label: @escaping () -> Label)Parameters
isCheckedA binding to the checkbox state.
labelPositionPosition of the label relative to the checkbox (defaults to
.trailing).labelA view builder that defines the label content.
-
The body of the checkbox view.
This includes the checkbox shape, checkmark, background fill, and optional label.
Declaration
Swift
@MainActor public var body: some View { get }