Skip to content

Instantly share code, notes, and snippets.

@c-villain
Created December 30, 2021 21:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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)
}
}
@ggoraa
Copy link

ggoraa commented Dec 30, 2021

These are super useful! Thanks!

@c-villain
Copy link
Author

@ggoraa enjoy!=)

@ggoraa
Copy link

ggoraa commented Jan 2, 2022

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