프로그래밍/Swift(IOS & Mac)
UIImagePickerController를 이용한 사진불러오기
낼은어떻게
2016. 1. 14. 19:25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import UIKit class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBAction func imgSelect(sender: AnyObject) { let picker = UIImagePickerController() picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary picker.allowsEditing = true picker.delegate = self self.presentViewController(picker, animated: false, completion: nil) } @IBOutlet var imgView: UIImageView! func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { picker.dismissViewControllerAnimated(false, completion: nil) self.imgView.image = info[UIImagePickerControllerOriginalImage] as? UIImage } func imagePickerControllerDidCancel(picker: UIImagePickerController) { picker.dismissViewControllerAnimated(false, completion: nil) let alert = UIAlertController(title: "", message: "이미지 선택이 취소되었습니다.", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "확인", style: .Cancel, handler: nil)) self.presentViewController(alert, animated: false, completion: nil) } } | cs |