What should I write to capture the same image that is displayed then save it to photo library
This is an image displayed in view. I want to save the displayed image in photo library.
You don't call the "save" function anywhere. You can call it, when you tapped on this image
struct SwiftUIView: View {
var body: some View {
HStack {
Image("car1")
.onTapGesture {
save()
}
}
}
func save(){
UIImageWriteToSavedPhotosAlbum(UIImage(named: "car1")!, nil, nil, nil)
}
}
Or create the button in HStack or VStack
struct SwiftUIView: View {
var body: some View {
HStack {
Image("car1")
Button("Save") {
save()
}
}
}
func save(){
UIImageWriteToSavedPhotosAlbum(UIImage(named: "car1")!, nil, nil, nil)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.