A component that displays a group of radio buttons, allowing users to select one option from multiple choices.
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.
Name | Type | Default | Description |
---|
animationScale | AnimationScale | medium | The scaling factor for the button's press animation, with a value between 0 and 1. |
color | UniversalColor | accent | The color of the selected radio button. |
font | UniversalFont? | nil | The font used for the radio items' titles. |
isEnabled | Bool | true | A 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. |
size | ComponentSize | medium | The predefined size of the radio buttons. |
spacing | CGFloat | 10 | The spacing between radio items. |
RadioItemVM Props
A model that defines the data and appearance properties for an item in a radio group.
Name | Type | Default | Description |
---|
id | ID | — | The unique identifier for the radio item. |
title | String | "" | The text displayed next to the radio button. |
font | UniversalFont? | nil | The font used for the item's title. |
isEnabled | Bool | true | A 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
Name | Type | Description |
---|
onSelectionChange | ((ID?) -> Void)? | A closure that is triggered when a selected segment changes. |
model | RadioGroupVM | A model that defines the appearance properties. |
selectedId | ID? | An identifier of the selected item. |
Public Subviews
Name | Type | Description |
---|
stackView | UIStackView | A stack view that contains radio button items. |
RadioGroupItemView
A view representing a single radio button item in a radio group.
Public Subviews
Name | Type | Description |
---|
radioView | UIView | A view that represents an outer circle and contains an inner circle. |
innerCircle | UIView | A view that represents an inner circle in the radio button. |
titleLabel | UILabel | A label that displays the title from the model. |