import SwiftUI struct LeftBorderView: View where Content: View { let color: Color let spacing: CGFloat let borderWidth: CGFloat private let content: Content init(color: Color, spacing: CGFloat, borderWidth: CGFloat, @ViewBuilder content: () -> Content) { self.color = color self.spacing = spacing self.borderWidth = borderWidth self.content = content() } var body: some View { HStack(spacing: spacing) { Rectangle() .fill(color) .frame(width: borderWidth) content }.fixedSize(horizontal: false, vertical: true) } } struct LeftBorderView_Previews: PreviewProvider { static var previews: some View { LeftBorderView(color: .orange, spacing: 5, borderWidth: 3) { Text("Some") } } }