SwiftUI – Picker/Radio Buttons – iOS equivalents of .radioGroup and .horizontalRadioGroupLayout()?

huangapple go评论59阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月21日 23:59:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定