Swift:如何分享imageview的图像?

时间:2016-07-14 17:13:23

标签: ios swift

imageview从Url加载图片

此代码用于保存图像

let indexPath = collectionView!.indexPathsForVisibleItems().last!
let cell = collectionView?.cellForItemAtIndexPath(indexPath) as! PhotoBrowserCell
if cell.imageView.image == nil{
    print("image nil")
} else {
    UIImageWriteToSavedPhotosAlbum(cell.imageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
}

cell.imageView.image我不知道如何使用share, 从imageview分享图片的最佳方式是什么

更新

我做了^ _ ^

此代码适用于从我的imageview分享

   let indexPath = collectionView!.indexPathsForVisibleItems().last!
        let cell = collectionView?.cellForItemAtIndexPath(indexPath) as! PhotoBrowserCell
         if let image = (cell.imageView.image)
        {
            let vc = UIActivityViewController(activityItems: [image], applicationActivities: [])
            self.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
   }

2 个答案:

答案 0 :(得分:2)

你问如何在iOS中实现共享?这是一个相当复杂的主题。您想阅读Xcode文档中的var readLines = File.ReadLines(this.Filepath) .Skip(rowStartAt).Take(numToTake) .Select(s => s.Split(new char[] { ',' }).Skip(timeStampCol) .Select(x => Convert.ToSingle(x)).ToList()).ToList(); ,也许还可以找到有关在iOS中实现共享的教程。

答案 1 :(得分:1)

我做了^ _ ^

此代码

   let indexPath = collectionView!.indexPathsForVisibleItems().last!
        let cell = collectionView?.cellForItemAtIndexPath(indexPath) as! PhotoBrowserCell
         if let image = (cell.imageView.image)
        {
            let vc = UIActivityViewController(activityItems: [image], applicationActivities: [])
            self.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
   }