Sets the section margins for specific edges in a List view, allowing precise control over spacing.
14.1% of iOS users can use this modifier
iOS 26+ required
.listSectionMargins(_:) Set margins for all edges
edges: EdgeInsets.listSectionMargins(_:edges:) Set margins for specific edges
insets: CGFloatedges: Edge.SetAdd horizontal margins to list sections
List {
Section("Settings") {
Text("Account")
Text("Privacy")
}
.listSectionMargins(20, edges: .horizontal)
}Apply custom margins with backward compatibility
List {
Section("Settings") {
Text("Account")
Text("Privacy")
}
.modifier(SectionMargins())
}
struct SectionMargins: ViewModifier {
func body(content: Content) -> some View {
if #available(iOS 26, *) {
content.listSectionMargins(20, edges: .horizontal)
} else {
content.padding(.horizontal, 20)
}
}
}Loading related modifiers...
If your app supports iOS versions older than 26, you can use #available to conditionally apply this modifier:
if #available(iOS 26, *) {
myView.listSectionMargins()
} else {
// Fallback for older iOS versions
myView
}Check the code examples above for specific #available patterns with this modifier.
The .listSectionMargins() modifier requires iOS 26 or later. This means 14.1% of current iOS users can use this modifier.
Yes! Use #available(iOS 26, *) to conditionally apply this modifier only on devices running iOS 26 or later, with a fallback for older versions.
Apply the .listSectionMargins() modifier to any SwiftUI view. Check the code examples above for usage patterns.
Visit the official Apple documentation for detailed information.