How can I set the spacing between sections of a list? I want 5 for first, 10 for second, 15 for third.
Asked on 2024-07-30
1 search
To set the spacing between sections of a list in SwiftUI, you can use the Section view along with custom spacing. Here's an example of how you can achieve different spacings for each section:
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Section(header: Text("First Section")) {
Text("Item 1")
Text("Item 2")
}
.padding(.bottom, 5) // 5 points spacing after the first section
Section(header: Text("Second Section")) {
Text("Item 1")
Text("Item 2")
}
.padding(.bottom, 10) // 10 points spacing after the second section
Section(header: Text("Third Section")) {
Text("Item 1")
Text("Item 2")
}
.padding(.bottom, 15) // 15 points spacing after the third section
}
}
}
In this example, each Section is followed by a .padding(.bottom, value) modifier to set the spacing after the section. Adjust the value to set the desired spacing for each section.
For more detailed information on working with sections in SwiftUI, you can refer to the session Demystify SwiftUI containers from WWDC 2024.

Get started with Dynamic Type
Dynamic Type lets people choose their preferred text size across the system and all of their apps. To help you get started supporting Dynamic Type, we’ll cover the fundamentals: How it works, how to find issues with scaling text in your app, and how to take practical steps using SwiftUI and UIKit to create a great Dynamic Type experience. We’ll also show how you can best use the Large Content Viewer to make navigation controls accessible to everyone.

What’s new in UIKit
Explore everything new in UIKit, including tab and document launch experiences, transitions, and text and input changes. We’ll also discuss better-than-ever interoperability between UIKit and SwiftUI animations and gestures, as well as general improvements throughout UIKit.

Demystify SwiftUI containers
Learn about the capabilities of SwiftUI container views and build a mental model for how subviews are managed by their containers. Leverage new APIs to build your own custom containers, create modifiers to customize container content, and give your containers that extra polish that helps your apps stand out.
