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

    isChecked

    A 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

    isChecked

    A binding to the checkbox state.

    label

    The text to display next to the checkbox.

    labelPosition

    Position 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

    isChecked

    A binding to the checkbox state.

    labelPosition

    Position of the label relative to the checkbox (defaults to .trailing).

    label

    A 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 }