Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created June 13, 2022 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupamchugh/19f76681139b8529eb389f7cba1d40ca to your computer and use it in GitHub Desktop.
Save anupamchugh/19f76681139b8529eb389f7cba1d40ca to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var exportImage: UIImage?
@State var bgColor = Color.blue
@State var text = "Hello, World!"
var body: some View {
VStack{
PosterView(bgColor: $bgColor, text: $text)
Form{
Section{
TextField("Enter Title", text: $text)
ColorPicker("Choose a background color", selection: $bgColor).padding(.horizontal)
}
Section{
Button("Export Poster"){
exportImage = ImageRenderer(content: PosterView(bgColor: $bgColor, text: $text)).uiImage
}
}
}
HStack{
if let exportImage{
Image(uiImage: exportImage)
.scaledToFill()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment