MaterialUIKit
Github
  • MaterialUIKit
  • Essentials
    • Configuring and Personalizing
    • Defining a Custom Color Schemes
  • Configuration and Color Schemes
    • MUIKitConfiguration
    • MUIKitColorScheme
  • Components
    • Action Button
      • ActionButtonStyle
    • Checkbox
    • Collection
      • CollectionStyle
    • Container
    • Date Selector
    • Dialog
    • Dialog Sheet
    • Dropdown Menu
      • Dropdown Menu Label
    • FAB
    • Icon Button
      • IconButtonStyle
    • Navigation Container
      • NavigationContainerHeaderStyle
      • Navigation Route
      • Navigation Route Label
    • Progress Bar
    • Radio Buttons Group
    • Search Box
    • Secure Text Box
    • Segmented Buttons
    • Separator
      • SeparatorOrientationStyle
    • Snackbar
    • Switch
    • Time Selector
    • Text Box
    • Tab Bar
      • TabBar Item
Powered by GitBook
On this page
  • Overview
  • Initializer
  • Parameters
  • Example
  1. Components

Radio Buttons Group

Represents a Material UI styled group of radio buttons for selecting a single option.​

Overview

Radio button groups are used to display a set of mutually exclusive options where only one can be selected at a time. They help users make a single choice from a predefined list of options.

The RadioButtonGroup view provides a Material UI styled set of radio buttons, making it easy to present and select options within a SwiftUI view.

To use the RadioButtonGroup, initialize it with a collection of items, a key path for unique identification, a binding to track the selected item, and a closure for rendering each item.

Initializer

Creates a radio button group view with the provided items and a binding to the selected value.

RadioButtonGroup(
    _ data: Data,
    id: KeyPath<Data.Element, ID>,
    selection: Binding<Data.Element>,
    @ViewBuilder _ content: @escaping (Data.Element) -> Content
)

Parameters

Parameter
Description

data

A collection of elements to display in the radio-group options.

id

A key path to an ID property on each element to uniquely identify them.

selection

A binding to the currently selected element in the radio-group options.

content

A closure that returns the content view for a given element.

Example

@State private var selectedOption: String = "Option 1"
private let options: [String] = ["Option 1", "Option 2", "Option 3"]

var body: some View {
    Collection {
        RadioButtonGroup(options, id: \.self, selection: $selectedOption) { option in
            Text(option)
        }
    }
}

RadioButtonGroup is compatible with custom data models that conform to Hashable and Identifiable protocols.

PreviousProgress BarNextSearch Box

Last updated 10 months ago