Spacing Between Sections in a Form

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.

demo

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 brs 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



Leave a reply



Submit