Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@IBAction func saveImage(_ sender: Any) {
contextImageView.image = UIImage(contentsOfFile: Bundle.main.path(forResource: "noimage", ofType: "png")!)!
UIGraphicsBeginImageContextWithOptions(contextImageView.bounds.size, false, 0)
imageView1.image?.draw(at: .zero)
imageView2.image?.draw(at: .zero)
let imageToShare = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
PHPhotoLibrary.requestAuthorization { _ in }
let shareItems = [imageToShare, "Hello"] as [Any]
let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activityController.popoverPresentationController?.sourceView = saveBtn
}
present(activityController, animated: true) { self.contextImageView.image = nil }
}
// or
@IBAction func saveImage(_ sender: Any) {
contextImageView.image = UIImage(contentsOfFile: Bundle.main.path(forResource: "noimage", ofType: "png")!)!
let imageToShare = UIGraphicsImageRenderer(size: contextImageView.bounds.size).image { _ in
imageView1.image?.draw(at: .zero)
imageView2.image?.draw(at: .zero)
}
PHPhotoLibrary.requestAuthorization { _ in }
let shareItems = [imageToShare, "Hello"] as [Any]
let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activityController.popoverPresentationController?.sourceView = saveBtn
}
present(activityController, animated: true) { self.contextImageView.image = nil }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.