//

//  ViewController.swift

//  ImagePicker

//

//  Created by stayfoolish on 2018. 8. 28..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit


class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{


    lazy var imagePicker: UIImagePickerController = {

        let picker: UIImagePickerController = UIImagePickerController()

        picker.sourceType = .photoLibrary

        picker.delegate = self

        return picker

    }()

    

    @IBOutlet weak var imageView: UIImageView!

    

    @IBAction func touchUpSelectImageButton(_ sender: UIButton){

        self.present(self.imagePicker, animated: true, completion: nil)

    }

    

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {

        self.dismiss(animated: true, completion: nil)

    }

    

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        

        if let originalImage: UIImage = info[UIImagePickerControllerOriginalImage] as? UIImage {

            self.imageView.image = originalImage

        }

        

        self.dismiss(animated: true, completion: nil)

    }

    

    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.

    }



}





+ Recent posts