如何添加库并使用ELCImagePickerController在swift 3 ios 10中选择多个图像

时间:2016-11-14 00:42:54

标签: swift swift3 elcimagepickercontroller

我是使用swift 3快速编码的新手。

我构建了我的应用程序以成功从photolib中选择图像,现在我正在尝试选择多个图像,我想知道在我的应用程序中使用ELCImagePickerController的步骤。

如何添加库以及允许我添加其相关代码并在我的Xcode中使用控制器及其所有功能的步骤? 简单地说,如何将第二方自定义代码嵌入到我的中?

2 个答案:

答案 0 :(得分:1)

Download whole working project

工作代码

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


}

有一个快乐的编码。

答案 1 :(得分:0)

导入UIKit 导入照片 导入BSImagePicker

类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: - 集合视图方法

扩展名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: - 收集单元

class imgCollectionViewCell:UICollectionViewCell {

    @IBOutlet var img1: UIImageView!