Post marked as unsolved
Click to stop watching this post.
You have stopped watching this post. Click to start watching again.
Post marked as unsolved with 9 replies
Replied In
Snapshot of a SwiftUI View
extension View {
func snapshot() - UIImage {
let controller = UIHostingController(rootView: self)
let view = controller.view
let targetSize = controller.view.intrinsicContentSize
view?.bounds = CGRect(origin: .zero, size: targetSize)
view?.backgroundColor = .systemBackground
let renderer = UIGraphicsImageRenderer(size: targetSize)
return renderer.image { _ in
view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
}
}
}
I think it can help I use this in swiftui it can be used in swift too
edit: I read all replies after posting