【发布时间】:2019-11-03 14:43:47
【问题描述】:
如何在NavigationView 中对齐Form。我有以下内容,当我从正文中删除 NaviagationView 时,Form 是顶部对齐的。使用NavigationView,我在两者之间获得了间距(添加了红色框以显示空间)。我可以在表单上使用.padding(.top, -20),但是虽然这可行,但它会稍微倾斜。
NavigationView {
Form {
VStack {
HStack {
Text("Name:").underline().font(.headline)
TextField("Name", text: $routine.name)
}
roundPicker()
TimeSelectionView(stateName: "A", stateDuration: "0:30", stateBackground: "#df405a")
TimeSelectionView(stateName: "B", stateDuration: "1:30", stateBackground: "#4ea1d3")
TimeSelectionView(stateName: "C", stateDuration: "3:00", stateBackground: "#4f953b")
}
}
.navigationBarTitle("Create", displayMode: .inline)
.navigationBarItems(trailing:
Button(action: {
//Save Routine
self.routine.rounds = self.roundsArray[self.rounds]
print("Workout Name: \(self.routine.name)")
print("Workout Rounds: \(self.routine.rounds)")
}, label: {
Text("Save")
}
)
)
}
【问题讨论】:
-
将
.listStyle(GroupedListStyle())应用于List视图时也会出现差距,并且接受的答案也适用于这种情况。