Last active
September 23, 2016 21:00
-
-
Save imack/133d98f1877eccd769fa to your computer and use it in GitHub Desktop.
Simple UIImagePicker Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// PhotoExample | |
// | |
// Created by Ian MacKinnon on 2016-09-23. | |
// Copyright © 2016 Ian MacKinnon. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate> | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
-(IBAction)showCamera:(id)sender{ | |
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
NSLog(@"Can't use Camera on simulator or your weird iPod from 2007"); | |
return; | |
} | |
UIImagePickerController * picker = [[UIImagePickerController alloc] init]; | |
picker.delegate = self; | |
picker.sourceType = UIImagePickerControllerSourceTypeCamera; | |
[self presentViewController:picker animated:true completion:nil]; | |
} | |
-(IBAction)showPhotoLibrary:(id)sender{ | |
UIImagePickerController * picker = [[UIImagePickerController alloc] init]; | |
picker.delegate = self; | |
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
[self presentViewController:picker animated:true completion:nil]; | |
} | |
- (void)imagePickerController:(UIImagePickerController *)picker | |
didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info;{ | |
UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; | |
[picker dismissViewControllerAnimated:YES completion:^{ | |
self.selectedImageView.image = selectedImage; | |
}]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment