Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swiftで画像を複数選択
import Photos
import DKImagePickerController // 忘れないように
/* classにUIImagePickerControllerを書き加える
例: class ViewController: UIViewController, UIImagePickerController {
*/
@IBOutlet weak var imageView: UIImageView!
let pickerController = DKImagePickerController()
// 選択可能な枚数を20にする
pickerController.maxSelectableCount = 20
pickerController.didSelectAssets = { [unowned self] (assets: [DKAsset]) in
// 選択された画像はassetsに入れて返却されるのでfetchして取り出す
for asset in assets {
asset.fetchFullScreenImage(completeBlock: { (image, info) in
// ここで取り出せる
self.imageView.image = image
})
}
}
self.present(pickerController, animated: true) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment