1

目前我已经picker包含在SectionForm想要达到的目标是将所选值与pickeriOS 13 和 14 中的前导对齐,我尝试了许多解决方案,例如labelsHidden()但没有结果,请找到在 iOS 14 上生成以下屏幕截图的代码示例,任何帮助将不胜感激在此处输入图像描述

struct ContentView: View {
    @State private var selectedStrength = "Mild"
    let strengths = ["Mild", "Medium", "Mature"]

    var body: some View {
        NavigationView {
            Form {
                Section {
                    Picker("", selection: $selectedStrength) {
                        ForEach(strengths, id: \.self) {
                            Text($0)
                        }
                    }
                }
            }
        }
    }
}
4

1 回答 1

2

在 a 中使用Text()with Spacer()aHStack()

struct ContentView: View {
    @State private var selectedStrength = "Mild"
    let strengths = ["Mild", "Medium", "Mature"]

    var body: some View {
        NavigationView {
            Form {
                Section {
                    Picker("", selection: $selectedStrength) {
                        ForEach(strengths, id: \.self) { t in
                            HStack {
                                Text(t)
                                Spacer()
                            }
                        }
                    }
                }
            }
        }
    }
}
于 2021-05-25T14:37:40.003 回答