Home

Awesome

SwiftPhotoGallery

Platform Version License CocoaPods tests Swift Dependencies

Overview

A full screen photo gallery for iOS and tvOS written in Swift.

<p align="center"> <img src="https://s3.amazonaws.com/inspirato-ios/SwiftPhotoGallery_animation.gif"> </p>

Usage

To run the example project, clone the repo, and run pod install from the Example directory.

Requirements

Communication

Installation

SwiftPhotoGallery is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftPhotoGallery'

Implementation

import SwiftPhotoGallery
let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)
gallery.backgroundColor = UIColor.black
gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
gallery.currentPageIndicatorTintColor = UIColor.white
gallery.hidePageControl = false
let imageNames = ["image1.jpeg", "image2.jpeg", "image3.jpeg"]

func numberOfImagesInGallery(gallery: SwiftPhotoGallery) -> Int {
    return imageNames.count
}

func imageInGallery(gallery: SwiftPhotoGallery, forIndex: Int) -> UIImage? {
    return UIImage(named: imageNames[forIndex])
}
func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
    // do something cool like:
    dismiss(animated: true, completion: nil)
}
present(gallery, animated: true, completion: nil)

Full Example

class ViewController: UIViewController, SwiftPhotoGalleryDataSource, SwiftPhotoGalleryDelegate {

    let imageNames = ["image1.jpeg", "image2.jpeg", "image3.jpeg"]
    var index: Int = 2

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func didPressShowMeButton(sender: AnyObject) {
        let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)

        gallery.backgroundColor = UIColor.black
        gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
        gallery.currentPageIndicatorTintColor = UIColor.white
        gallery.hidePageControl = false

        present(gallery, animated: true, completion: nil)

        /*
        /// Or load on a specific page like this:

        present(gallery, animated: true, completion: { () -> Void in
            gallery.currentPage = self.index
        })
        */

    }

    // MARK: SwiftPhotoGalleryDataSource Methods

    func numberOfImagesInGallery(gallery: SwiftPhotoGallery) -> Int {
        return imageNames.count
    }

    func imageInGallery(gallery: SwiftPhotoGallery, forIndex: Int) -> UIImage? {
        return UIImage(named: imageNames[forIndex])
    }

    // MARK: SwiftPhotoGalleryDelegate Methods

    func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
        dismiss(animated: true, completion: nil)
    }
    
}

Author

Justin Vallely, justinvallely@gmail.com

License

SwiftPhotoGallery is available under the Apache License 2.0. See the LICENSE file for more info.