So I finally got around to polishing up my photo gallery, MTGallery. I’ve put together all the code in an Example Xcode Project on GitHub. It supports all orientations, page numbers, and captions. There’s an NSOperationQueue to throttle downloads, and some basic caching.

mtgallery_portrait

All you need to use it is my .h, .m, and .xib and an array of URLs.

Take a look:

- (IBAction) launchGallery:(id)sender
{
    // Make sure to hide the status bar before called presentModalViewController (and not withing MTGalleryViewController itself).
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    NSMutableArray *myPhotos = [[NSMutableArray alloc] init];
    [myPhotos addObject:@"http://www.luminous-landscape.com/images64/gallery4741-thumb.jpg"];
    [myPhotos addObject:@"http://www.secondspacegallery.com/images/Second-Space-Gallery_for-we.jpg"];
    [myPhotos addObject:@"http://images.politico.com/global/portland.jpg"];
    [myPhotos addObject:@"http://www.cape-verde-holiday.com/kitesurf.jpg"];
    [myPhotos addObject:@"http://www.reuk.co.uk/OtherImages/repower-5mw-wind-turbine.jpg"];
    [myPhotos addObject:@"http://www.luminous-landscape.com/images64/gallery4741-thumb.jpg"];
    [myPhotos addObject:@"http://www.secondspacegallery.com/images/Second-Space-Gallery_for-we.jpg"];

    NSMutableArray *myCaptions = [[NSMutableArray alloc] init];
    [myCaptions addObject:@"Gallery 1"];
    [myCaptions addObject:@"Gallery 2"];
    [myCaptions addObject:@"Portland"];
    [myCaptions addObject:@"Kiting"];
    [myCaptions addObject:@"Energy"];

    MTGalleryViewController *controller = [[MTGalleryViewController alloc] initWithPhotos:myPhotos andCaptions:myCaptions];    

    [self presentModalViewController:controller animated:YES]; 

    [myPhotos release];
    [myCaptions release];

    [controller release];
}

About the Author: Matt Tuzzolo

Matt is, most recently, an iPhone and iPad developer. He is interested in social responsibility, technology, food, electric cars, and things like that. "I hope you find my posts helpful or interesting in some way."