Skip to content

Instantly share code, notes, and snippets.

@c-villain
Created December 30, 2021 21:13
Show Gist options
  • Save c-villain/c91b9bfb02205979e8b31d5f3e7235cb to your computer and use it in GitHub Desktop.
Save c-villain/c91b9bfb02205979e8b31d5f3e7235cb to your computer and use it in GitHub Desktop.
Must-have SwiftUI frame extensions
extension View {
// MARK: Vertical Center
func vCenter() -> some View {
self
.frame(maxHeight: .infinity, alignment: .center)
}
// MARK: Vertical Top
func vTop() -> some View {
self
.frame(maxHeight: .infinity, alignment: .top)
}
// MARK: Vertical Bottom
func vBottom() -> some View {
self
.frame(maxHeight: .infinity, alignment: .bottom)
}
// MARK: Horizontal Center
func hCenter() -> some View {
self
.frame(maxWidth: .infinity, alignment: .center)
}
// MARK: Horizontal Leading
func hLeading() -> some View {
self
.frame(maxWidth: .infinity, alignment: .leading)
}
// MARK: Horizontal Trailing
func hTrailing() -> some View {
self
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
@voltangle
Copy link

These are super useful! Thanks!

@c-villain
Copy link
Author

@ggoraa enjoy!=)

@voltangle
Copy link

https://github.com/ggoraa/SwiftUIUtils created a Swift Package for things like this :D

@c-villain
Copy link
Author

@ggoraa nice one!

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