rania
rania

Reputation: 57

How to add libraries and use ELCImagePickerController to select multiple images in swift 3 ios 10

I am new to swift coding using swift 3.

I built my app to select images from photolib successfully, now I am trying to select multiple images, I want to know the steps to use the ELCImagePickerController in my app.

How can I add the libraries and the steps that will let me can add its related code and use the controller and all its feature in my Xcode? Simply, how to embed a second party custom made code into mine?

Upvotes: 0

Views: 973

Answers (2)

Hasya
Hasya

Reputation: 9898

Download whole working project

Working code

import UIKit


class ViewController: UIViewController, ELCImagePickerControllerDelegate {

    var picker = ELCImagePickerController(imagePicker: ())
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    
    override func viewDidAppear(animated: Bool) {
        
        picker.maximumImagesCount = 5
        picker.imagePickerDelegate = self
        self.presentViewController(picker, animated: true, completion: nil)

        
    }
    
    func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
        
    }
    
    
    func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {
        
    }
   
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

Upvotes: 1

Hiren
Hiren

Reputation: 270

import UIKit import Photos import BSImagePicker

class ViewController: UIViewController {

//MARK:- Outlets

@IBOutlet var collView: UICollectionView!
@IBOutlet var img: UIImageView!

//MARK:- Variable

var Select = [PHAsset]()
var arrimg = [UIImage]()

override func viewDidLoad() {
    super.viewDidLoad()

// imgPkr.delegate = self }

//MARK:- Button Action

@IBAction func btnSelect(_ sender: AnyObject) {

    let imgPkr = BSImagePickerViewController()

self.bs_presentImagePickerController(imgPkr, animated: true, select: {(asset : PHAsset) -> Void in }, deselect: {(asset : PHAsset) -> Void in}, cancel: {(assets : [PHAsset]) -> Void in}, finish: {(assets : [PHAsset]) -> Void in

    for i in 0..<assets.count
    {
        self.Select.append(assets[i])

    }
    }, completion: nil)}

func getAllImg() -> Void
{

    if Select.count != 0{
    for i in 0..<Select.count{
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.isSynchronous = true
    manager.requestImage(for: Select[i], targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in
            thumbnail = result!
        })

        self.arrimg.append(thumbnail)
    }
    }

    collView.reloadData()


}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.perform(#selector(ViewController.getAllImg), with: nil, afterDelay: 0.5)
}

} // MARK:- Collection View Method

extension ViewController : UICollectionViewDataSource,UICollectionViewDelegate{

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return arrimg.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! imgCollectionViewCell

    cell.img1.image = arrimg[indexPath.item]

    return cell
}

}

//MARK :- Collection Cell

class imgCollectionViewCell: UICollectionViewCell {

    @IBOutlet var img1: UIImageView!

Upvotes: 0

Related Questions