XCode 12 Beta 3 SwiftUI Space between sections on a form
Try to add the following in the View containing Form
init() {
UITableView.appearance().sectionHeaderHeight = .zero
}
Reduce Form spacing between sections SwiftUI
The possible solution is to use custom a-la group separator, instead of standard.
Tested with Xcode 11.4 / iOS 13.4 on some replicated code.
List {
ForEach(array.indices, id: \.self) { i in
VStack(spacing: 0) {
Text(self.array[i].title)
.padding(.horizontal)
Text(self.array[i].content)
.padding(.horizontal)
if i != self.array.count - 1 { // don't show for last
Rectangle().fill(Color(UIColor.systemGroupedBackground))
.frame(height: 16) // << fit as you need
}
}.listRowInsets(EdgeInsets()) // << avoid extra space
}
}.listStyle(GroupedListStyle())
How to eliminate the space above Section in SwiftUI Form?
The solution is to use a Section
with an EmptyView()
and place the view you want to be at the top in the header of this Section
var body: some View {
VStack {
Text("Text 1")
Form {
Section(header: VStack(alignment: .center, spacing: 0) {
Text("Text 2").padding(.all, 16)
.frame(width: UIScreen.main.bounds.width, alignment: .leading)
.background(Color.white)
}) {
EmptyView()
}.padding([.top], -6)
}
}
}
spacing between form fields
I would wrap your rows in labels
<form action="doit" id="doit" method="post">
<label>
Name
<input id="name" name="name" type="text" />
</label>
<label>
Phone number
<input id="phone" name="phone" type="text" />
</label>
<label>
Year
<input id="year" name="year" type="text" />
</label>
</form>
And use
label, input {
display: block;
}
label {
margin-bottom: 20px;
}
Don't use br
s for spacing!
Demo: http://jsfiddle.net/D8W2Q/
How do you put space between two objects in the same row
You can research about a gap property that adds space between flex and grid elements. It will suit you too instead of br
tags to add vertical space between the image, the form and the set of buttons.
I do not recommend to use padding for this purpose since this property is for inner spacing of an element, between its content and border. Read more about CSS Box Model.
The very common property for spacing between elements is margin. It works not only between flex and grid elements.
I also recommend you to use Developer Tools in Chrome and Firefox browsers to see a clear picture what you are actually getting in browsers and why.
Bootstrap - spacing between form-inline elements
That space is generated by the property inline-block
is compared to treating the elements as text, if you have on your markup each element on a new line this generates a space and each element is a "new word".
Check the Snippet
section { background:white; margin:20px auto;}div { display:inline-block; height:50px; width:30%; margin:20px auto; background:red; border:thin solid orange}
<section> <div></div> <div></div> <div></div></section>
SwiftUI Form Label above Text field Section Spacing
My second answer to my own question. This is what I came up with.
I decided to go down the route of a separate label above a text input control using the header as the label. This does have a different look.
This is simply because the original look I was after didn't have the best UI experience.
It is possible to add extra code but it starts to get far to over complicated.
Form {
Section(header: Text("Field1") // Label
.font(.headline)
.foregroundColor(.black)
// The padding top is larger on the first control to make it stand out more from the navigation bar title.
.padding(EdgeInsets(top: 30, leading: 5, bottom: 0, trailing: 0))) {
TextField("Required", text: $Field1)
}
.textCase(nil) // I dont want the label to be all uppercase.
Section(header: Text("Field2") // Label
.font(.headline)
.foregroundColor(.black)
.padding(EdgeInsets(top: 0, leading: 5, bottom: 0, trailing: 0))) {
TextField("Required", text: $Field1)
}
.textCase(nil)
Section {
NavigationLink(destination: SomeView()) {
Text("Next")
.padding()
.foregroundColor(Color.blue)
}
}
}
.navigationBarTitle("Main Title")
Related Topics
How to Write a Generic Function for Floating Point Values in Swift
Add Assets to an Icloud Shared Photo Album Programmatically
Animation Triggered Using a Button Stops a Repeatforever Animation Added Onappear
How to Cut a Hole in a Sprite Image or Texture to Show What Is Behind It Using Spritekit in Swift
Nsurlsession Upload File to Server Swift
Swiftui Conditional View Transitions Are Not Working
Cache That Can Purge Unused Objects by Demand
How to Use Mtlblitcommandencoder for Copying Interlaced Video Fields into a Mtlbuffer
Swift Custom Response Serializer Is Returning Images at Random
How to Import Zbar Framework in Swift Project
A Warning "'Init()' Is Deprecated". [Swift, iOS App, Learning Model]
Cloudkit - What to Do When a User Adds, Modifies or Deletes an Object While Offline
How to Have a Searchbar Which Shows Suggestions with Different UItableview
How to Bind My Array Controller to My Core Data Model
Nssavepannel - How to Restrict User to Only Save One One Set Directory
Uicollectionview + Nsfetchedresultscontroller in Swift 3
Thread Safety of Method Calls on "Shared" Static Constant Property