我有快速倡议的观点,提出了若干<代码>。 GridRows in a Grid
. 每一行各有2栏,左栏为统一,右栏为左栏。 每一行都有标题(左栏)和数据领域(右栏)。
<代码>Text Fields和Pickers
按我的期望行事,与栏左侧一致。 但<代码>DatePicker将只与其栏右侧一致。
我曾尝试过:
- Placing a
Spacer()
after theDatePicker
- Putting the
DatePicker
insideVStack(alignment: .leading)
within itsGridRow
任何人都知道如何将日期推向左边的其他牢房?
如下:
import SwiftUI
struct ContentView: View {
@State var name = ""
@State var date = Date()
@State var house = Int()
var body: some View {
NavigationStack {
ScrollView {
VStack(alignment: .leading) {
Grid(alignment: .leading) {
GridRow {
Text("Name (Image(systemName: "person")):")
.font(.headline)
.gridColumnAlignment(.trailing)
TextField("Full name", text: $name)
.font(.body)
.padding(.horizontal, 10)
.padding(.vertical, 5)
.background(Color(UIColor.systemBackground))
.cornerRadius(8)
.gridColumnAlignment(.leading)
}
GridRow {
Text("Birthdate (Image(systemName: "calendar")):")
.font(.headline)
DatePicker("", selection: $date, displayedComponents: .date)
}
GridRow {
Text("House (Image(systemName: "house")):")
.font(.headline)
Picker("", selection: $house) {
Text("Gryffindor").tag(1)
Text("Slytherin").tag(2)
Text("Ravenclaw").tag(3)
Text("Hufflepuff").tag(4)
}
}
}
}
.padding(10)
.background(RoundedRectangle(cornerRadius: 10)
.fill(Color.gray
.gradient
.opacity(0.15)))
}
.padding(.horizontal)
.navigationTitle("Add Wizard Info")
.navigationBarTitleDisplayMode(.inline)
}
}
}