RadioButton
@MainActor
public struct RadioButton<T> : View where T : Hashable
A customizable radio button component that conforms to the current Theme.
RadioButton supports generic Hashable values and automatically updates the selected value.
You can display a custom label on either side of the button.
Example:
RadioButton(selection: $selectedOption, value: .optionA, labelPosition: .trailing) {
Text("Option A")
}
-
Initializes a radio button without a label.
Declaration
Swift
@MainActor public init(selection: Binding<T>, value: T, labelPosition: HorizontalPosition = .trailing)Parameters
selectionA binding to the currently selected value.
valueThe value this radio button represents.
labelPositionThe side on which the label should appear (defaults to
.trailing). -
Initializes a radio button with a custom label view.
Declaration
Swift
@MainActor public init<Label: View>(selection: Binding<T>, value: T, labelPosition: HorizontalPosition = .trailing, @ViewBuilder label: @escaping () -> Label)Parameters
selectionA binding to the currently selected value.
valueThe value this radio button represents.
labelPositionThe side on which the label should appear (defaults to
.trailing).labelA view builder providing the label content.
-
The visual body of the radio button view.
It displays a circle with an optional filled inner circle if selected, along with optional label content.
Declaration
Swift
@MainActor public var body: some View { get }