Swiftui:将选择器中选定的文本与前缘对齐

Hes*_*mal 5 swiftui swiftui-form ios14 swiftui-navigationview

目前,我已经picker包含在 aSectionForm,我想要达到的目标是将所选值picker与 iOS 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)
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

mah*_*han 7

在 a 中使用 theText()和 aSpacer()HStack()

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()
                            }
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)