// // ViewController.h // TakePhoto // // Created by UEC on 17/10/16. // Copyright (c) 2016年 Unisoft. All rights reserved. // #import @interface ViewController : UIViewController - (IBAction)onTakePhoto:(id)sender; - (IBAction)onGetPhoto:(id)sender; @property (weak, nonatomic) IBOutlet UIImageView *myPhotoImageView; @end _______________________ // // ViewController.m // TakePhoto // // Created by UEC on 17/10/16. // Copyright (c) 2016年 Unisoft. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onTakePhoto:(id)sender { UIImagePickerController *controller = [[UIImagePickerController alloc]init]; controller.delegate = self; // Photo from camera or file ? controller.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:controller animated:YES completion:nil]; } - (IBAction)onGetPhoto:(id)sender { UIImagePickerController *controller = [[UIImagePickerController alloc]init]; controller.delegate = self; // Photo from camera or file ? controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:controller animated:YES completion:nil]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // Handle the captured image here UIImage *myphoto = info[UIImagePickerControllerOriginalImage]; self.myPhotoImageView.image = myphoto; [picker dismissViewControllerAnimated:YES completion:nil]; } -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { // When click cancel [picker dismissViewControllerAnimated:YES completion:nil]; } @end