0

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?

Julien Marrec
  • 11,605
  • 4
  • 46
  • 63
rania
  • 57
  • 7
  • Hi, welcome to Stack Overflow. Unfortunately this isn't a homework service. Please explain what you have tried so far. Please read [How to Ask a good question](http://stackoverflow.com/help/how-to-ask) and [mcve](http://stackoverflow.com/help/mcve) – Julien Marrec Nov 16 '16 at 09:51
  • I did not get what do you mean by homework service, I had a problem that I faced during my development process and I asked it clearly and I think the question is clear enough - any way, I got it myself and I can consider it closed now. – rania Nov 17 '16 at 03:29

2 Answers2

1

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.
    }


}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Hasya
  • 9,792
  • 4
  • 31
  • 46
0

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!
Hiren
  • 260
  • 3
  • 3