38
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【iOS】【Swift】画像を複数枚選択するライブラリ『ELCImagePickerController』を使う

Posted at

写真を複数枚選択するのは標準に無いので、ライブラリを使う。

ELCImagePickerController

GitHub: https://github.com/B-Sides/ELCImagePickerController

コード

import UIKit

class ViewController: UIViewController, ELCImagePickerControllerDelegate {
    

    @IBAction func addButton(sender: AnyObject) {
        self.pickImages()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    // 写真を選択する
    func pickImages() {
        let picker = ELCImagePickerController()
        picker.maximumImagesCount = 5  // 選択する最大枚数
        picker.imagePickerDelegate = self
        self.presentViewController(picker, animated: true, completion: nil)
    }
    
    //  写真選択時に呼び出される
    func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
        self.dismissViewControllerAnimated(true, completion: nil)
        if (info.count == 0) {
            return
        }
        var pickedImages = NSMutableArray()
        for any in info {
            let dict = any as NSMutableDictionary
            let image = dict.objectForKey(UIImagePickerControllerOriginalImage) as UIImage
            pickedImages.addObject(image)
        }
        println(pickedImages)
    }
    
    // 写真未選択時に呼び出される
    func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

٩(๑❛ᴗ❛๑)۶

38
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?