UIGraphicsBeginImageContextWithOptions(controller.view.bounds.size, true, 0.0)
doesn’t help in this case
private var tile: some View {
.....
}
var body: some View {
GeometryReader { proxy in
VStack(alignment: .center, spacing: ShareViewConstants.primarySpacing) {
self.tile.frame(maxHeight: proxy.size.height * xxx)
....
}
}
.onTapGesture {
UIImageWriteToSavedPhotosAlbum(tile.snapshot(), nil, nil, nil)
self.isPresented = true
}
}
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 = .clear
let renderer = UIGraphicsImageRenderer(size: targetSize)
return renderer.image { _ in
view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
}
}
}