GithubHelp home page GithubHelp logo

archideus / rigimagegallery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rightpoint/rigimagegallery

0.0 2.0 0.0 15.81 MB

An image gallery view controller designed to work with the Raizlabs Interface Guidelines for iOS

License: Other

Ruby 6.06% Objective-C 1.17% Swift 92.77%

rigimagegallery's Introduction

RIGImageGallery

An image gallery for iOS

Build Status Version License Platform Carthage compatible

RIGImageGallery is a photo gallery meant to provide most of the functionality of the image gallery in the system Photos app, and handle asynchronous loading of images.

This library is part of the Raizlabs Interface Guidelines, which are UI components that offer sensible defaults to help a project get off the ground quickly with components that feel native to the platform, and with easy to use customization options.

RIGImageGallery

Features

  • Swipe to advance
  • Pinch to zoom
  • Double tap to toggle 1:1 zoom
  • Single tap to hide the nav bar

Requirements

  • iOS 9.0+
  • Xcode 8.0+

Installation with CocoaPods

CocoaPods

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

pod 'RIGImageGallery'

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/RIGImageGallery.framework to an iOS project.

github "Raizlabs/RIGImageGallery"

Manually

  1. Download all of the .swift files in RIGImageGallery/ and drop them into your project.
  2. Congratulations!

Usage example

To see a complete example of using the gallery, take a look at the sample project.

Creating a Gallery from Image URLs

func createPhotoGallery() -> RIGImageGalleryViewController {

    let urls: [URL] = [
          "https://placehold.it/1920x1080",
          "https://placehold.it/1080x1920",
          "https://placehold.it/350x150",
          "https://placehold.it/150x350",
        ].flatMap(URL.init(string:))

    let rigItems: [RIGImageGalleryItem] = urls.map { _ in
        RIGImageGalleryItem(placeholderImage: UIImage(named: "placeholder") ?? UIImage(),
                            isLoading: true)
    }

    let rigController = RIGImageGalleryViewController(images: rigItems)

    for (index, URL) in urls.enumerated() {
        let request = imageSession.dataTask(with: URLRequest(url: URL)) { [weak rigController] data, _, error in
            if let image = data.flatMap(UIImage.init), error == nil {
                rigController?.images[index].image = image
                rigController?.images[index].isLoading = false
            }
        }
        request.resume()
    }

    return rigController
}

Presenting and Customizing the View Controller

@objc func showGallery(_ sender: UIButton) {
    let photoViewController = createPhotoGallery()
    photoViewController.dismissHandler = dismissPhotoViewer
    photoViewController.actionButtonHandler = actionButtonHandler
    photoViewController.actionButton = UIBarButtonItem(barButtonSystemItem: .action, target: nil, action: nil)
    photoViewController.traitCollectionChangeHandler = traitCollectionChangeHandler
    photoViewController.countUpdateHandler = updateCount
    let navigationController = UINavigationController(rootViewController: photoViewController)
    present(navigationController, animated: true, completion: nil)
}

func dismissPhotoViewer(_ :RIGImageGalleryViewController) {
    dismiss(animated: true, completion: nil)
}

func actionButtonHandler(_: RIGImageGalleryViewController, galleryItem: RIGImageGalleryItem) {
}

func updateCount(_ gallery: RIGImageGalleryViewController, position: Int, total: Int) {
    gallery.countLabel.text = "\(position + 1) of \(total)"
}

func traitCollectionChangeHandler(_ photoView: RIGImageGalleryViewController) {
    let isPhone = UITraitCollection(userInterfaceIdiom: .phone)
    let isCompact = UITraitCollection(verticalSizeClass: .compact)
    let allTraits = UITraitCollection(traitsFrom: [isPhone, isCompact])
    photoView.doneButton = photoView.traitCollection.containsTraits(in: allTraits) ? nil : UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
}

Contributing

Issues and pull requests are welcome! Please ensure that you have the latest SwiftLint installed before committing and that there are no style warnings generated when building.

Contributors are expected to abide by the Contributor Covenant Code of Conduct.

License

RIGImageGallery is available under the MIT license. See the LICENSE file for more info.

Author

Michael Skiba, mailto:[email protected] @atelierclkwrk

rigimagegallery's People

Contributors

ateliercw avatar jwatson avatar zeveisenberg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.