XCode 12 Beta 3 SwiftUI 表单上各部分之间的空间
Posted
技术标签:
【中文标题】XCode 12 Beta 3 SwiftUI 表单上各部分之间的空间【英文标题】:XCode 12 Beta 3 SwiftUI Space between sections on a form 【发布时间】:2020-07-24 15:22:38 【问题描述】:如何为以下视图减少表单上各部分之间的间距?
var body: some View
Form
Section
TextField("Name", text: $patient.name, onEditingChanged: changed in
if !isNewPatient
isSaveDisabled = false
, onCommit:
if !isNewPatient
isSaveDisabled = false
)
.validation(patient.nameValidation)
TextField("Surname", text: $patient.surname)
.validation(patient.surnameValidation)
TextField("ID Number", text: $patient.id)
.validation(patient.idValidation)
.validation(patient.idRegexValidation)
.disabled(!self.isNewPatient)
.foregroundColor(isNewPatient ? .black : .gray)
Section
TextField("Street Number and Name", text: $patient.street)
TextField("Suburb", text: $patient.suburb)
TextField("Area Code", text: $patient.postCode)
.validation(patient.postCodeRegexValidation)
.isHidden(isDependant, remove: true)
Section
Picker("Medical Aid", selection: $patient.medicalAidName)
ForEach(medicalAids, id: \.self)
Text($0)
TextField("Medical Aid Number", text: $patient.medicalAidNo)
.isHidden(isDependant, remove: true)
Section
Button("Save")
if isNewPatient
if patient.create(moc: moc, isDependant: isDependant, mainID: self.mainID)
isDependantsActive.toggle()
else
if patient.update(moc: moc)
self.presentationMode.wrappedValue.dismiss()
.disabled(self.isSaveDisabled)
NavigationLink("Dependants", destination:
DependantListView(filter: mainID).environment(\.managedObjectContext, moc), isActive: $isDependantsActive
).disabled(isNewPatient).isHidden(isDependant, remove: true)
.onReceive(patient.allRequiredValidation) validation in
if isNewPatient
self.isSaveDisabled = !validation.isSuccess
.navigationBarTitle(title, displayMode: .inline)
这是表单的外观:
我查看了以下答案,但它们是不可接受的: Spacing between sections in a form
【问题讨论】:
【参考方案1】:尝试在包含Form
的View中添加以下内容
init()
UITableView.appearance().sectionHeaderHeight = .zero
【讨论】:
它可以工作,除非该部分有标题,在这种情况下没有变化。以上是关于XCode 12 Beta 3 SwiftUI 表单上各部分之间的空间的主要内容,如果未能解决你的问题,请参考以下文章
未找到 SwiftUI 符号:_$s7SwiftUI9TextFieldVAA4ViewAAMc Xcode 11 beta 3
SwiftUI Xcode 11 beta 7 @Binding for collections 正在打破预览
Xcode 12.0 12A7209 SwiftUI 错误:编译器无法在合理的时间内对该表达式进行类型检查
如何在数组大小更改后刷新 ForEach 显示元素的数量(SwiftUI,Xcode 11 Beta 5)
SwiftUI dyld:找不到符号:_$s7SwiftUI7BindingVyxGAA0C11ConvertibleAAMc Xcode 11 beta 5