iOS photo gallery written in Swift

Overview

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 9.0+
  • tvOS 10.0+
  • Xcode 10.2.1+
  • Swift 5.0+

Communication

  • If you need help, use Stack Overflow. (Tag 'swiftphotogallery')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

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.black
gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
gallery.currentPageIndicatorTintColor = UIColor.white
gallery.hidePageControl = false
  • 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:
    dismiss(animated: true, completion: nil)
}
  • Present the gallery
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, [email protected]

License

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

Comments
  • Opening SwiftGallery and changing orientation doesn't work

    Opening SwiftGallery and changing orientation doesn't work

    After opening a Gallery, I am encountering 2 problems.

    1. In portrait, if there is a large amount of photos, the page control goes outside of the view and looks weird.

    2. If I swift the orientation while in the gallery

    screen shot 2017-04-06 at 11 11 02 pm screen shot 2017-04-06 at 11 10 48 pm

    The pictures go off kilter and don't line up properly and skip.

    Is there a way to fix these issues? Love the gallery, just wanted to see if I could touch up a couple things.

    help wanted 
    opened by Viktorfalkner 16
  • GPLv3 exception is needed for 3rd parties to distribute on the App Store

    GPLv3 exception is needed for 3rd parties to distribute on the App Store

    For more information about why this is required, please read this blog post: https://whispersystems.org/blog/license-update/

    Here is how they resolved the issue:

    Additional Permissions For Submission to Apple App Store: Provided that you are otherwise in compliance with the GPLv3 for each covered work you convey (including without limitation making the Corresponding Source available in compliance with Section 6 of the GPLv3), Open Whisper Systems also grants you the additional permission to convey through the Apple App Store non-source executable versions of the Program as incorporated into each applicable covered work as Executable Versions only under the Mozilla Public License version 2.0 (https://www.mozilla.org/en-US/MPL/2.0/).

    opened by chrisballinger 9
  • Page controller off by 1 when setting currentPage after presenting

    Page controller off by 1 when setting currentPage after presenting

    By using the README recommended code to navigate to a specific page:

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

    the result is that the images in the array do not match the index of the pageControl. There is some sort of race condition with presenting the view controller, setting the pageControl.currentPage, and setting currentPage.

    opened by mpatzer 8
  • i can't get the images to zoom

    i can't get the images to zoom

    when i try to zoom my images they start zooming only to bounce back to their original size and double tap won't work i installed the example and tried it the first two images zooms perfectly but the last one have the same issue as mine here is my code

    func openGallery(_ btn: UIButton){
            let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)
            
            gallery.backgroundColor = UIColor.black
            gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
            gallery.currentPageIndicatorTintColor = UIColor.white
            present(gallery, animated: false) {
                gallery.currentPage = btn.tag;
            }
            
        }
    
    extension CarInfoVC: SwiftPhotoGalleryDataSource, SwiftPhotoGalleryDelegate {
        func numberOfImagesInGallery(gallery: SwiftPhotoGallery) -> Int {
            return imgArr.count
        }
        
        func imageInGallery(gallery: SwiftPhotoGallery, forIndex: Int) -> UIImage? {
            
            return UIImage(named: imgArr[forIndex])
        }
        
        // MARK: SwiftPhotoGalleryDelegate Methods
        
        func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
            dismiss(animated: true, completion: nil)
        }
    }
    
    opened by aliaziada 5
  • Explicitly setting current page

    Explicitly setting current page

    Hi!

    First, thanks a lot for a great lib!

    Now, I have a question. Is there a way how to explicitly say which image should be shown when the user opens the gallery? e.g. I have a collection of several thumbnails and I want to open a gallery scrolled to the specific image. Is this possible? I was trying to setup the currentPage property before I present the gallery but it always shows the first image.

    Thanks!

    opened by marcelmika 5
  • Subclassing failure:

    Subclassing failure: "cannot inherit from non-open class outside of its defining module"

    I am trying to add a "Share" button to the Photo Gallery and I liked @LunaCodeGirl 's answer from Issue #45 of subclassing SwiftPhotoGallery, however attempting this results in the error: "cannot inherit from non-open class outside of its defining module"

    Apparently Swift 3 introduced the 'open' versus 'public' access level as explained in this Stackoverflow answer

    So, I tried to achieve my Share button with an Extension instead, but overriding viewDidLoad() in an Extension blocks the superclass viewDidLoad() from being called, even with super.viewDidLoad()

    The result of using an Extension to add a share button to the photo gallery is that the Page Control Indicator and Tap to Dismiss Gesture are not functioning, because SwiftPhotoGallery.viewDidLoad() is not being called.

    Alas, this is not a detrimental UI failure, seeing as I can add a Close button alongside the Share button. But the eye-catchiness of the Photo Gallery is extremely cheapened without the Page Indicator and Swipe/Tap To Close gesture animations. I guess I'll just replicate the behavior in my class or Extension, if possible, or try method swizzling as described at NSHipster

    Please consider updating your package to the 'open' access level so that it may be subclassed as @LunaCodeGirl answered.

    See code excerpts, (it doesn't matter where super.viewDidLoad() is in the method, it never gets called-- I added print() statements to SwiftPhotoGallery.viewDidLoad() to check)

    extension SwiftPhotoGallery {
        
        public override func viewDidLoad() {
            //super.viewDidLoad()
            
            // create the share button
            let shareButton: UIButton! = UIButton(type: .custom)
            
            // configure the share button
            var buttonImage: UIImage!
            let buttonTintColor: UIColor = UIColor.white
            buttonImage = UIImage(named: "share-alt")?.withRenderingMode(.alwaysTemplate)
            shareButton.setImage(buttonImage, for: .normal)
            shareButton.tintColor = buttonTintColor
            
            shareButton.translatesAutoresizingMaskIntoConstraints = false
            
            var shareButtonConstraints: [NSLayoutConstraint] = []
            
            shareButtonConstraints.append(NSLayoutConstraint(item: shareButton,
                                                             attribute: .top,
                                                             relatedBy: .equal,
                                                             toItem: view,
                                                             attribute: .top,
                                                             multiplier: 1,
                                                             constant: 20))
            
            shareButtonConstraints.append(NSLayoutConstraint(item: shareButton,
                                                             attribute: .trailing,
                                                             relatedBy: .equal,
                                                             toItem: view,
                                                             attribute: .trailing,
                                                             multiplier: 1,
                                                             constant: -16))
            
            shareButtonConstraints.append(NSLayoutConstraint(item: shareButton,
                                                              attribute: .height,
                                                              relatedBy: .equal,
                                                              toItem: nil,
                                                              attribute: .notAnAttribute,
                                                              multiplier: 1,
                                                              constant: 25))
            
            shareButtonConstraints.append(NSLayoutConstraint(item: shareButton,
                                                             attribute: .width,
                                                             relatedBy: .equal,
                                                             toItem: nil,
                                                             attribute: .notAnAttribute,
                                                             multiplier: 1,
                                                             constant: 25))
            
            // Add the share button to the view.
            view.addSubview(shareButton)
            view.addConstraints(shareButtonConstraints)
            view.insertSubview(shareButton, aboveSubview: imageCollectionView)
            
            shareButton.addTarget(self, action: #selector(self.shareButtonClicked(_:)), for: .touchUpInside)
            super.viewDidLoad()
        }
    
    //MARK: - sharing activity methods
        
        // method attached to the Share button to display the Share dialog
        func shareButtonClicked(_ sender: UIButton) {
            let appDelegate = UIApplication.shared.delegate as! AppDelegate
            
            // show the share sheet, passing it the current image being displayed so it can be saved & shared by the user
            displayShareSheet(shareContent: appDelegate.photoGalleryImages[currentPage])
        }
        
        // shows the Sharing system activity screen so that the user can easily save/share app content images;
        // must also add Privacy Permission Description to Info.plist so that the user can save images to the Photos library
        // https://blog.xamarin.com/new-ios-10-privacy-permission-settings/
        // https://developer.apple.com/library/content/qa/qa1937/_index.html
        // https://stackoverflow.com/questions/35931946/basic-example-for-sharing-text-or-image-with-uiactivityviewcontroller-in-swift
        func displayShareSheet(shareContent: UIImage) {
            // instantiate the sharing activity, passing it the image to save/share
            let activityViewController = UIActivityViewController(activityItems: [shareContent as UIImage], applicationActivities: nil)
            
            // must include a sourceView for iPad compatibility (crashes on iPad without sourceView)
            activityViewController.popoverPresentationController?.sourceView = self.view
            
            // display the sharing dialog
            present(activityViewController, animated: true, completion: {})
        }
    }
    
    opened by rajathooja 4
  • Images with url not working for this library

    Images with url not working for this library

    I am appending images from an api which gives me the url. I tried appending url process for UIImage but its not working. Can you please tell me how to do that

    opened by ahmed-sharief5 3
  • Rotation bug when going from portrait to Landscape on 1st image

    Rotation bug when going from portrait to Landscape on 1st image

    I tried out the example that is included. on iPHone 6,7,8 I tested it.

    1. When in full screen mode (tap on one of the images)
    2. When you have first photo up
    3. When going from Portrait to Landscape there are 2 photos. being displayed during rotation.
    opened by marcvanolmen 3
  • How does this integrate at all with SDWebImage

    How does this integrate at all with SDWebImage

    Your delegate methods need an optional UIImage, however SDWebImage sets an image on an ImageView.

    Am I supposed to create a random ImageView and pass back the image I get from SDWebImage?

    Or how do I utilize this library with SDWebImage?

    opened by Viktorfalkner 3
  • iOS 12 Image jump right-down

    iOS 12 Image jump right-down

    Hi,

    Only with iOS 12, the image loaded moves down and right after less than a second. I have attached an example:

    1 2

    I'm working to find and fix this issue. @Inspirato, do you have any idea what is happening?

    Thanks!

    opened by xvicient21 2
  • Image download from Url

    Image download from Url

    Hello . first of all you have created great library swiftphotogalley. I am downloading images from url and those images I want to show on collectionview . please do help.

    opened by nikhil191090 2
  • Update Page Control with Number of Images

    Update Page Control with Number of Images

    Great code, update pageControl when getting "numberOfImagesInGallery" to keep it in sync.

    SwiftPhotoGallery.swift file public func collectionView(_ imageCollectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { let numberOfImages = dataSource?.numberOfImagesInGallery(gallery: self) ?? 0 self.pageControl.numberOfPages = numberOfImages return(numberOfImages) }

    opened by ejuden 0
  • Fixed iPad multitasking issue

    Fixed iPad multitasking issue

    When gallery view runs on iPad with multitasking enabled, the image is not placed in centre. Because the size of header and footer was set to screen size which doesn't equal view size in multitasking mode.

    opened by xyxy616161 1
Releases(3.4.1)
  • 3.4.1(May 14, 2019)

  • 3.3.1(Dec 22, 2017)

    3.3.1 (2017-12-21)

    Enhancements
    • Changes license from GNU to Apache 2.0 (Big thanks to chrisballinger)
    Bug Fixes
    • Fixes content inset adjustment in the example project. This will not affect your projects.
    Source code(tar.gz)
    Source code(zip)
  • 3.3.0(Dec 4, 2017)

  • 3.2.2(Oct 26, 2017)

    Bug Fixes
    • Fixes bug when rotation occurs on first image and content is offset, or header display causing last page to be scrolled to during that rotation
    • Fixes issue for isViewFirstAppearing not being called in certain conditions
    • Improves accuracy and efficiency of revolving carousel when header or footer is reached
    • Implements fix to prevent infinite scrolling when only one image is present
    • Fixes unit tests
    Source code(tar.gz)
    Source code(zip)
  • 3.2.1(Oct 19, 2017)

  • 3.2.0(Oct 18, 2017)

    Enhancements
    • DROPS SUPPORT FOR IOS 8
    • Adds revolving gallery carousel. Swipe through last image to get to the first image. (enabled by default)
    • Opens up imageView and scrollView access level
    • Updates Nimble to 7.0.2 for unit tests on the example project.
    • Updates README.md
    Source code(tar.gz)
    Source code(zip)
  • 3.1.3(Aug 4, 2017)

  • 3.1.2(Aug 4, 2017)

    Enhancements
    • Example project: Converted to a more common collection view
    • Example project: adds presenting and dismissing animators using UIPresentationController and UIViewControllerAnimatedTransitioning
    • General code cleanup
    • Updates README.md
    Bug Fixes
    • Fixes image flash when loading gallery to a specific page
    Source code(tar.gz)
    Source code(zip)
  • 3.1.1(Aug 1, 2017)

  • 3.1.0(Jan 25, 2017)

  • 3.0.1(Nov 14, 2016)

  • 3.0.0(Oct 6, 2016)

  • 2.0.6(Sep 27, 2016)

    This will be the last supported version 2 release. SwiftPhotoGallery version 3 will migrate code to Swift 3 and all future development will move forward from there.

    Source code(tar.gz)
    Source code(zip)
  • 2.0.5(Jul 21, 2016)

    Finally! That goofy bug where the images would scroll by 2 on the first swipe when entering the gallery is fixed.

    There's also a new, more robust method for calculating the current page.

    And a big thanks to @merrickluo for adding code to hide the page control.

    Source code(tar.gz)
    Source code(zip)
  • 2.0.4(May 3, 2016)

  • 2.0.3(Apr 29, 2016)

  • 2.0.2(Apr 29, 2016)

Owner
Justin Vallely
Staff iOS Engineer at Ibotta. Specializing in app infrastructure and mobile payments.
Justin Vallely
Nilay Dagdemir 0 Jan 23, 2022
Jogendra 113 Nov 28, 2022
DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.

DTPhotoViewerController Example Demo video: https://youtu.be/aTLx4M4zsKk DTPhotoViewerController is very simple to use, if you want to display only on

Tung Vo 277 Dec 17, 2022
An iOS/tvOS photo gallery viewer, useful for viewing a large (or small!) number of photos.

This project is unmaintained. Alex passed away in an accident in late 2019. His love of iOS development will always be remembered. AXPhotoViewer AXPho

Alex Hill 596 Dec 30, 2022
This simple cordova plugin will download picture from an URL and save to IOS Photo Gallery.

Photo Viewer This plugin is intended to download a picture from an URL into IOS Photo library.. How to Install Cordova: cordova plugin add https://git

Alwin jose 1 Oct 23, 2021
Photo Gallery App demo using a REST API

Photo Gallery iOS App - (Using Rest API) A demo Photo Gallery App using a Rest API using MVVM architecture in Swift + UIKit. Overview Fully Programmat

Neel Mewada 2 Nov 22, 2021
DGCropImage - A photo cropping tool which mimics Photo.app written by Swift

DGCropImage A photo cropping tool which mimics Photo.app written by Swift. This

donggyu 11 Jul 14, 2022
React-native-photo-editor - Photo editor using native modules for iOS and Android

?? Image editor using native modules for iOS and Android. Inherit from 2 available libraries, ZLImageEditor (iOS) and PhotoEditor (Android)

Baron Ha. 244 Jan 5, 2023
Photo-Sharing-App - Photo Sharing App With Swift

Photo Sharing App You can register and log in to this application and share your

Yağız Savran 2 Jun 14, 2022
IRGallery-swift is a powerful gallery for iOS.

IRGallery-swift IRGallery-swift is a powerful gallery for iOS. Features Captions. Rotation support. Load images locally or from a web URL. Custom UITa

Phil Chang 1 Oct 6, 2021
🖼 Gallery App for Actomaton (async/await + Elm Architecture) + SwiftUI.

?? Actomaton-Gallery Gallery App for Actomaton (async/await + Elm Architecture) + SwiftUI. NOTE: Most of the code are reused from Harvest-SwiftUI-Gall

Yasuhiro Inami 44 Dec 20, 2022
Applies filter to a selected image from the Gallery using Combine

CombinePhotoFiltering App CombinePhotoFiltering is an app that applies sepia and bloom to a selected picture from the Photos app. Highlights The app i

Mauricio Esteves 0 Nov 14, 2021
Gallery has a clearer flow based on albums and focuses on the use case of selecting video

Description We all love image pickers, don't we? You may already know of ImagePicker, the all in one solution for capturing pictures and selecting ima

null 1 Sep 14, 2022
Image gallery similar to Adidias' app, built in SwiftUI

TripleStackGallery TripleStackGallery is a image gallery component, which displays a set of images as a stack of three images, always displaying the i

Tomás Martins 5 Aug 29, 2022
FacebookImagePicker is Facebook album photo picker written in Swift.

Features • Installation • Usage • Translation • License GBHFacebookImagePicker is Facebook's album photo picker written in Swift, built to provide a s

Florian Gabach 231 Dec 17, 2022
Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift

SKPhotoBrowser [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-) Simple PhotoBrowser

keishi suzuki 2.4k Jan 6, 2023
Lightweight iOS Photo Blur App

Blurry Blurry is the go-to image blurring tool to help you apply beautiful blurs for your photos. It is perfect for creating wallpapers, backgrounds,

Andy 17 Nov 22, 2022
A modern photo viewing experience for iOS.

NYTPhotoViewer NYTPhotoViewer is a slideshow and image viewer that includes double-tap to zoom, captions, support for multiple images, interactive fli

The New York Times 2.8k Jan 5, 2023
An image cropper / photo cropper for iOS like in the Contacts app with support for landscape orientation.

RSKImageCropper An image cropper for iOS like in the Contacts app with support for landscape orientation. Installation RSKImageCropper requires iOS 9.

Ruslan Skorb 2.4k Jan 5, 2023