Advertisement
Don_Mag

Untitled

May 5th, 2023
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.58 KB | None | 0 0
  1. struct ContentView: View {
  2.    
  3.     var textView: some View {
  4.         Text("Hello, SwiftUI")
  5.             .padding()
  6.             .background(.red)
  7.             .foregroundColor(.white)
  8.             .clipShape(Capsule())
  9.     }
  10.    
  11.     var body: some View {
  12.         VStack {
  13.             textView
  14.                 .onTapGesture {
  15.                     let renderer = ImageRenderer(content: textView)
  16.                    
  17.                     if let uiImage = renderer.uiImage {
  18.                         print("created UIImage - size:", uiImage.size)
  19.                         if let d = uiImage.jpegData(compressionQuality: 0.9) {
  20.                             print("image as jpeg data successful")
  21.                             // use the data somehow
  22.                         }
  23.                     }
  24.                 }
  25.         }
  26.     }
  27.    
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement