Here i have used third party library BSImagePicker to do multiple selection in our gallery .After selecting the image i cant be able to save and display in the image view .I want the image to be save and display in the collection view .I have imported photos and BSImagePicker.
If i click showImagepicker the multiple images can be selected and it should place in the respective position .I have used 4 image view to set the images which we have selected . Here is my code :
class ViewController: UIViewController ,UICollectionViewDataSource,UICollectionViewDelegate{
@IBAction func showImagePicker(_ sender: UIButton) {
let vc = BSImagePickerViewController()
vc.maxNumberOfSelections = 4
bs_presentImagePickerController(vc, animated: true,
select: { (asset: PHAsset) -> Void in
print("Selected: \(asset)")
}, deselect: { (asset: PHAsset) -> Void in
print("Deselected: \(asset)")
}, cancel: { (assets: [PHAsset]) -> Void in
print("Cancel: \(assets)")
}, finish: { (assets: [PHAsset]) -> Void in
print("Finish: \(assets)")
if let imageView = vc.imageview{
PHCachingImageManager.default().requestImage(for: asset, targetSize:imageView.frame.size, contentMode: .aspectFit, options: options) { (result, _) in
imageView.image = result
}
}
}, completion: nil)
}
@IBOutlet weak var collectionview: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
cell.imagecollection.image = imageview[indexPath.row]
return cell
}
Here is the custom view class for collectionviewcell:
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imagecollection: UIImageView!
@IBOutlet weak var imageview2: UIImageView!
@IBOutlet weak var imageview3: UIImageView!
@IBOutlet weak var imageview4: UIImageView!
}
I have used 4 outlet of the image view.I need to save in this imageview.