Don_Mag icon

Untitled

Don_Mag | PRO | 05/05/23 04:28:49 PM UTC | 0 ⭐ | 8119 👁️ | Never ⏰ | []
Swift |

580 B

|

None

|

0 👍

/

0 👎

struct ContentView: View {
    
    var textView: some View {
        Text("Hello, SwiftUI")
            .padding()
            .background(.red)
            .foregroundColor(.white)
            .clipShape(Capsule())
    }
    
    var body: some View {
        VStack {
            textView
                .onTapGesture {
                    let renderer = ImageRenderer(content: textView)
                    
                    if let uiImage = renderer.uiImage {
                        print("created UIImage - size:", uiImage.size)
                        if let d = uiImage.jpegData(compressionQuality: 0.9) {
                            print("image as jpeg data successful")
                            // use the data somehow
                        }
                    }
                }
        }
    }
    
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎