Last active
December 15, 2022 17:05
-
-
Save thepearl/9ea24cf6181c3f155c53c4c54d0f35a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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