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