Skip to content

Instantly share code, notes, and snippets.

@thepearl
Last active December 15, 2022 17:05
Show Gist options
  • Save thepearl/9ea24cf6181c3f155c53c4c54d0f35a7 to your computer and use it in GitHub Desktop.
Save thepearl/9ea24cf6181c3f155c53c4c54d0f35a7 to your computer and use it in GitHub Desktop.
struct WrapperView<Content: View>: View {
let content: () -> Content
init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
var body: some View {
VStack(alignment: .center) {
content()
.padding()
.background(Color.gray)
.cornerRadius(10)
.shadow(radius: 5)
}
}
}
// Apply padding, background, cornerRadius.. to a Text.
WrapperView {
Text("Hello")
}
// Apply padding, background, cornerRadius.. to a Button.
WrapperView {
Button("Hello button") {
print("hi")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment