Hey all,

This is a simple post showing how you can open the “Gallery” or “Photos” application in iOS.

The Sample UI should look like this.

Select image from Gallery in ios

Screenshot selecting image from the Gallery.

Select image from gallery in ios

Now to the code.


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UINavigationControllerDelegate,

@property (strong, nonatomic) IBOutlet UIImageView* imageView;

- (IBAction) pickImage:(id)sender;



#import "ViewController.h"

@interface ViewController ()


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

- (IBAction) pickImage:(id)sender{
    UIImagePickerController *pickerController = [[UIImagePickerController alloc]
    pickerController.delegate = self;
    [self presentViewController:pickerController animated:YES completion:nil];

#pragma mark -
#pragma mark UIImagePickerControllerDelegate

- (void) imagePickerController:(UIImagePickerController *)picker
         didFinishPickingImage:(UIImage *)image
                   editingInfo:(NSDictionary *)editingInfo
    self.imageView.image = image;
    [self dismissModalViewControllerAnimated:YES];

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];


We add “UINavigationControllerDelegate,UIImagePickerControllerDelegate” to get the events after selecting the image from
the Gallery.

The below function is called after selecting image from Gallery

– (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo

You can download the complete source code from here.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.