RadioGroup

@MainActor
public struct RadioGroup<T> : View where T : Hashable

A vertically stacked group of radio buttons bound to a single selection.

RadioGroup allows presenting multiple options where only one can be selected at a time. It supports both simple String labels or custom label views.

RadioGroup(selection: $selectedOption, options: MyEnum.allCases) { option in
    Text(option.rawValue)
}
  • Creates a RadioGroup with string-based labels.

    Declaration

    Swift

    @MainActor
    public init(
      selection: Binding<T>,
      options: [T],
      labelPosition: HorizontalPosition = .trailing,
      labelProvider: @escaping (T) -> String
    )

    Parameters

    selection

    Binding to the selected value.

    options

    Array of options to display.

    labelPosition

    Position of label relative to radio (default is .trailing).

    labelProvider

    Closure that returns a String for each option.

  • Creates a RadioGroup with custom SwiftUI label views.

    Declaration

    Swift

    @MainActor
    public init<Label: View>(
      selection: Binding<T>,
      options: [T],
      labelPosition: HorizontalPosition = .trailing,
      @ViewBuilder labelProvider: @escaping (T) -> Label
    )

    Parameters

    selection

    Binding to the selected value.

    options

    Array of options to display.

    labelPosition

    Position of label relative to radio (default is .leading).

    labelProvider

    View builder closure that returns a view for each option.

  • The view body that renders all radio buttons in a vertical layout.

    Declaration

    Swift

    @MainActor
    public var body: some View { get }