34 lines
693 B
Swift
34 lines
693 B
Swift
import SwiftUI
|
|
|
|
/**
|
|
A view that centers the content vertically using a `VStack`
|
|
*/
|
|
struct VerticalCenter<Content> : View where Content : View {
|
|
|
|
let alignment: HorizontalAlignment
|
|
|
|
let spacing: CGFloat?
|
|
|
|
let content: Content
|
|
|
|
public init(alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content) {
|
|
self.alignment = alignment
|
|
self.spacing = spacing
|
|
self.content = content()
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: alignment, spacing: spacing) {
|
|
Spacer()
|
|
content
|
|
Spacer()
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VerticalCenter {
|
|
Text("Test")
|
|
}
|
|
}
|