如何在 SwiftUI 中创建单选按钮? [英] How to create Radiobuttons in SwiftUI?
本文介绍了如何在 SwiftUI 中创建单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对用户的选择做出反应.类似于此示例的内容:
I would like to react on a choice of a user. Something similar to this example:
在第二阶段,我想在每个单选按钮下方显示其他内容,例如将按钮 2 和 3 相互移动以提供允许的网站列表.
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.
到目前为止,我还没有找到如何在 SwiftUI 中执行此操作.非常感谢!
So far I haven't found how to do this in SwiftUI. Many thanks in advance!
推荐答案
Picker(selection: $order.avocadoStyle, label: Text("Avocado:")) {
Text("Sliced").tag(AvocadoStyle.sliced)
Text("Mashed").tag(AvocadoStyle.mashed)
}.pickerStyle(RadioGroupPickerStyle())
这是来自 2019 swiftUI Essentials 主题演讲的代码(SwiftUI Essentials- WWDC 2019.视频中大约 43 分钟他们展示了这个例子.
This is the code from the 2019 swiftUI essentials keynote (SwiftUI Essentials - WWDC 2019. Around 43 minutes in the video they show this example.
它看起来像这样:
这篇关于如何在 SwiftUI 中创建单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文