Search code examples
swiftui

How to create Radiobuttons in SwiftUI?


I would like to react on a choice of a user. Something similar to this example: 4 Radiobuttons

In a 2nd stage would I like to show additional content below each radiobutton, e.g. moving the buttons 2 and 3 from each other in order to give a list of websites for allowing.

So far I haven't found how to do this in SwiftUI. Many thanks in advance!


Solution

  • Picker(selection: $order.avocadoStyle, label: Text("Avocado:")) { 
        Text("Sliced").tag(AvocadoStyle.sliced) 
        Text("Mashed").tag(AvocadoStyle.mashed)
    }.pickerStyle(RadioGroupPickerStyle())
    

    This is the code from the 2019 swiftUI essentials keynote (SwiftUI Essentials - WWDC 2019. Around 43 minutes in the video they show this example.

    It will look like this:

    radio button group