Radio Group

A component that displays a group of radio buttons, allowing users to select one option from multiple choices.

Preview

Button Preview

Code Example

enum Coffee {
  case cappuccino
  case latte
  case flatWhite
}

let model = RadioGroupVM<Coffee> {
  $0.items = [
    .init(id: .cappuccino) {
      $0.title = "Cappuccino"
    },
    .init(id: .latte) {
      $0.title  = "Latte"
    },
    .init(id: .flatWhite) {
      $0.title = "Flat White"
      $0.isEnabled = false
    }
  ]
  $0.color = .success
  $0.animationScale = .large
  $0.size = .large
}

API

RadioGroupVM Props

A model that defines the appearance properties for a radio group component.

NameTypeDefaultDescription
animationScaleAnimationScalemediumThe scaling factor for the button's press animation, with a value between 0 and 1.
colorUniversalColoraccentThe color of the selected radio button.
fontUniversalFont?nilThe font used for the radio items' titles.
isEnabledBooltrueA Boolean value indicating whether the radio group is enabled or disabled.
items[RadioItemVM<ID>][]An array of items representing the options. Must contain at least one item with unique identifiers.
sizeComponentSizemediumThe predefined size of the radio buttons.
spacingCGFloat10The spacing between radio items.

RadioItemVM Props

A model that defines the data and appearance properties for an item in a radio group.

NameTypeDefaultDescription
idIDThe unique identifier for the radio item.
titleString""The text displayed next to the radio button.
fontUniversalFont?nilThe font used for the item's title.
isEnabledBooltrueA Boolean value indicating whether the item is enabled or disabled.

SURadioGroup

public init(
  selectedId: Binding<ID?>,
  model: RadioGroupVM<ID>
)

UKRadioGroup

Initializers

public init(
  initialSelectedId: ID? = nil,
  model: RadioGroupVM<ID>,
  onSelectionChange: ((ID?) -> Void)? = nil
)

Public Properties

NameTypeDescription
onSelectionChange((ID?) -> Void)?A closure that is triggered when a selected segment changes.
modelRadioGroupVMA model that defines the appearance properties.
selectedIdID?An identifier of the selected item.

Public Subviews

NameTypeDescription
stackViewUIStackViewA stack view that contains radio button items.

RadioGroupItemView

A view representing a single radio button item in a radio group.

Public Subviews

NameTypeDescription
radioViewUIViewA view that represents an outer circle and contains an inner circle.
innerCircleUIViewA view that represents an inner circle in the radio button.
titleLabelUILabelA label that displays the title from the model.