使用 UIActivityViewController 共享图像

Share an image using UIActivityViewController

我想使用 UIActivityViewController 分享图片。我可以显示我想分享的文字,但我真的不知道如何添加图片。希望有人能帮助我。谢谢!

我的代码显示在"actionButton"

import UIKit

class DetailViewController: UIViewController, UIScrollViewDelegate {

    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var myDetailedImageView: UIImageView!

    var myDetailedImageName: String?
    var nameString: String?

    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        //For setting max and min zoom
        scrollView.maximumZoomScale = 0.8
        scrollView.minimumZoomScale = 0.15
        scrollView.delegate = self
        //reset zoomzcale for new image
        self.scrollView.zoomScale = 0.15
        self.myDetailedImageView.image = UIImage(named: myDetailedImageName!)
    }

    @IBAction func actionButton(sender: AnyObject) {
        let firstActivityItem = NSString(string: myDetailedImageName!)
        let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
        self.presentViewController(activityViewController, animated: true, completion: nil)
    }

    //Showing what to zoom/scroll
    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
        //returning image to reload it self
        return myDetailedImageView
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

就像文字一样:

let activityViewController = UIActivityViewController(activityItems: [firstActivityItem, self.myDetailedImageView.image!], applicationActivities: nil)