我想使用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.
}
}
答案 0 :(得分:1)
就像文字一样:
let activityViewController = UIActivityViewController(activityItems: [firstActivityItem, self.myDetailedImageView.image!], applicationActivities: nil)