luicm / SwiftPhotoGallery

iOS photo gallery written in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwiftPhotoGallery

Platform Version License CocoaPods tests Swift Dependencies

Overview

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

  • Photos can be panned and zoomed (iOS only)
  • Pinch to zoom (iOS only)
  • Double tap to zoom all the way in and again to zoom all the way out (iOS only)
  • Single tap to close
  • Twitter style swipe to close (iOS only)
  • Includes a customizable page indicator
  • Support for any orientation (iOS only)
  • Supports images of varying sizes
  • Includes unit tests
  • Customize nearly all UI aspects
  • Integrates seamlessly with SDWebImage

Usage

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

Requirements

  • iOS 8.3+
  • tvOS 10.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

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

pod "SwiftPhotoGallery"

Implementation

  • Import the framework in your view controller
import SwiftPhotoGallery
  • Create an instance
let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)
  • Customize the look
gallery.backgroundColor = UIColor.blackColor()
gallery.pageIndicatorTintColor = UIColor.grayColor().colorWithAlphaComponent(0.5)
gallery.currentPageIndicatorTintColor = UIColor.whiteColor()
  • Implement the datasource
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])
}
  • Implement the delegate
func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
  // do something cool like:
  dismissViewControllerAnimated(true, completion: nil)
}
  • Full example:
class ViewController: UIViewController, SwiftPhotoGalleryDataSource, SwiftPhotoGalleryDelegate {

    let imageNames = ["image1.jpeg", "image2.jpeg", "image3.jpeg"]

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

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

        gallery.backgroundColor = UIColor.blackColor()
        gallery.pageIndicatorTintColor = UIColor.grayColor().colorWithAlphaComponent(0.5)
        gallery.currentPageIndicatorTintColor = UIColor.whiteColor()

        presentViewController(gallery, animated: true, completion: nil)
    }

    // 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) {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
}

Author

Justin Vallely, jvallely@inspirato.com

License

SwiftPhotoGallery is available under the GNU General Public License. See the LICENSE file for more info.

About

iOS photo gallery written in Swift

License:GNU General Public License v2.0


Languages

Language:Swift 82.5%Language:Objective-C 8.5%Language:Shell 8.4%Language:Ruby 0.6%