Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created September 29, 2016 15:52
Show Gist options
  • Save KentarouKanno/55692d1076d6aaee4769696d1ed5c79b to your computer and use it in GitHub Desktop.
Save KentarouKanno/55692d1076d6aaee4769696d1ed5c79b to your computer and use it in GitHub Desktop.
QBImagePicker

QBImagePicker

questbeat/QBImagePicker

import UIKit

class ViewController: UIViewController {

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


}

import UIKit
import QBImagePicker

class SecondViewController: UIViewController,QBImagePickerControllerDelegate {
    
    @IBOutlet weak var imageView1: UIImageView!
    @IBOutlet weak var imageView2: UIImageView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    @IBAction func album(sender: AnyObject) {
        pickImages()
    }
    
    func pickImages(){
        
        let picker = QBImagePickerController()
        picker.delegate = self
        picker.allowsMultipleSelection = true
        picker.minimumNumberOfSelection = 1
        picker.maximumNumberOfSelection = 2
        picker.showsNumberOfSelectedAssets = true
        
        presentViewController(picker, animated: true, completion: nil)
    }
    
    func qb_imagePickerController(imagePickerController: QBImagePickerController!, didFinishPickingAssets assets: [AnyObject]!) {
        
        for asset in assets {
            
            let manager = PHImageManager.defaultManager()
            let option = PHImageRequestOptions()
            var thumbnail = UIImage()
            option.synchronous = true
            manager.requestImageForAsset(asset as! PHAsset, targetSize: CGSize(width: 100.0, height: 100.0), contentMode: .AspectFit, options: option, resultHandler: {(result, info)->Void in
                thumbnail = result!
                
            })
        }
        
        dismissViewControllerAnimated(true,completion: nil)
    }
    
    func qb_imagePickerControllerDidCancel(picker: QBImagePickerController!) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment