Post

Replies

Boosts

Views

Activity

Reply to 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
Apr ’21