Skip to content

Instantly share code, notes, and snippets.

@amirdew
Created December 22, 2022 13:20
Show Gist options
  • Save amirdew/a7ee19de9fb9a2139e94ef155b6f5e9b to your computer and use it in GitHub Desktop.
Save amirdew/a7ee19de9fb9a2139e94ef155b6f5e9b to your computer and use it in GitHub Desktop.
Minimum paddings for SwiftUI views
extension View {
func minimumPadding(edges: Edge.Set = .all, _ length: CGFloat = 8) -> some View {
GeometryReader { geo in
padding(.bottom, edges.contains(.bottom) ? max(length, geo.safeAreaInsets.bottom) : 0)
.padding(.top, edges.contains(.top) ? max(length, geo.safeAreaInsets.top) : 0)
.padding(.leading, edges.contains(.leading) ? max(length, geo.safeAreaInsets.leading) : 0)
.padding(.trailing, edges.contains(.trailing) ? max(length, geo.safeAreaInsets.trailing) : 0)
.ignoresSafeArea(edges: edges)
}
}
}
@amirdew
Copy link
Author

amirdew commented Dec 22, 2022

minimumpadding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment