Skip to content

Repository files navigation

SwiftPhotoGallery

VersionLicensePlatformCocoaPodstestsSwift

Usage

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

-Pinch to zoom. -Double tap to zoom all the way in and again to zoom all the way out. -Single tap to close.

-Supports images of varying sizes.

-Includes unit test.

Requirements

  • iOS 8.3+
  • 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
letgallery=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
letimageNames=["image1.jpeg","image2.jpeg","image3.jpeg"]func numberOfImagesInGallery(gallery:SwiftPhotoGallery)->Int{return imageNames.count
}func imageInGallery(gallery:SwiftPhotoGallery, forIndex:Int)->UIImage?{returnUIImage(named:imageNames[forIndex])}
  • Implement the delegate
func galleryDidTapToClose(gallery:SwiftPhotoGallery){
// do something cool like:
dismissViewControllerAnimated(true, completion:nil)}
  • Full example:
classViewController:UIViewController,SwiftPhotoGalleryDataSource,SwiftPhotoGalleryDelegate{letimageNames=["image1.jpeg","image2.jpeg","image3.jpeg"]overridefunc viewDidLoad(){
super.viewDidLoad()}@IBActionfunc didPressShowMeButton(sender:AnyObject){letgallery=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?{returnUIImage(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

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages