英文:
SwiftUI - Picker/Radio Buttons - iOS equivalents of .radioGroup and .horizontalRadioGroupLayout()?
问题
需要在我的应用程序中添加一些单选按钮。在SwiftUI中是否已删除此功能?有很多帖子讨论人们如何自己创建单选按钮,但很难相信这种基本功能竟然不存在?
以前的示例代码可能如下:
VStack(spacing: 20) {
Picker(selection: $selected, label: Text("Favorite Fruit")) {
Text("Apple").tag(1)
Text("Orange").tag(2)
Text("Banana").tag(3)
Text("Kiwi").tag(4)
}
.pickerStyle(.radioGroup)
.horizontalRadioGroupLayout()
}
注意:.pickerStyle(.radioGroup)
和 .horizontalRadioGroupLayout()
不是当前 iOS 的功能。
英文:
I need to add some Radio Buttons to my App. Has this been removed in SwiftUI? There are lots of posts of people cutting their own Radio Buttons but can't believe something this fundamental doesn't exist, somehow?
Previous sample code would have been like:
VStack(spacing: 20) {
Picker(selection: $selected, label: Text("Favorite Fruit")) {
Text("Apple").tag(1)
Text("Orange").tag(2)
Text("Banana").tag(3)
Text("Kiwi").tag(4)
}
.pickerStyle(.radioGroup)
.horizontalRadioGroupLayout()
}
n.b .pickerStyle(.radioGroup) & .horizontalRadioGroupLayout() are not current iOS.
答案1
得分: 1
只适用于 macOS 10.15+。
https://developer.apple.com/documentation/swiftui/view/horizontalradiogrouplayout()
https://developer.apple.com/documentation/swiftui/pickerstyle/radiogroup
要支持 iOS,您必须自行创建。
英文:
.pickerStyle(.radioGroup)
.horizontalRadioGroupLayout()
Are only for macOS 10.15+
https://developer.apple.com/documentation/swiftui/view/horizontalradiogrouplayout()
https://developer.apple.com/documentation/swiftui/pickerstyle/radiogroup
To support iOS you have to create your own.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论