//
// 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.
}
}
'Swift > 기초&문법' 카테고리의 다른 글
스위프트 swift 클로저 (0) | 2018.08.30 |
---|---|
스위프트 swift class vs struct / enum 클래스 vs 구조체 / 열거형 (0) | 2018.08.29 |
스위프트 swift music player 음악재생 앱 (0) | 2018.08.27 |
스위프트 swift 피커뷰 원하는 이미지 선택 (0) | 2018.08.24 |
스위프트 swift 데이트 피커 사용해 날짜 선택하는 앱 (0) | 2018.08.24 |