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
Post
Replies
Boosts
Views
Activity
still don't know how I fixed this but I fixed this I think it fixed itself
if someone found this try to merge all your scrollTo in a Foreach (I merged the else if wichView.SelectedView == 5 and the else if wichView.SelectedView == 9 and it works but still don't know why it doesn't work with different conditions)