Swiftui:将选择器中的选定文本与前缘对齐
Swiftui: align selected text in picker to leading edge
目前我有一个 picker
包含在一个 Section
中包含在一个 Form
中,我想要达到的是对齐 [=11= 的选定值] 在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([=10=])
}
}
}
}
}
}
}
在 HStack()
中使用 Text()
和 Spacer()
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()
}
}
}
}
}
}
}
}
目前我有一个 picker
包含在一个 Section
中包含在一个 Form
中,我想要达到的是对齐 [=11= 的选定值] 在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([=10=])
}
}
}
}
}
}
}
在 HStack()
Text()
和 Spacer()
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()
}
}
}
}
}
}
}
}