Created
November 1, 2014 07:37
-
-
Save yat1ma30/d4b54d182263a1a5bf95 to your computer and use it in GitHub Desktop.
【iOS】【Swift】画像を複数枚選択するライブラリ『ELCImagePickerController』を使う ref: http://qiita.com/ottati/items/b86a8a11f1b54564c738
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment