Giter Site home page Giter Site logo

janephotobrowser's Introduction

Jane Photo Browser

Overview

The JanePhotoBrowser is a scrolling photo gallary written in Swift 3. The API to interface with the photo browser is similar to the APIs used in UITableViews and UICollectionViews and should have a familiar feel.

PhotoBrowser

Features

  • Easy setup: Just add a PhotoBrowserView to your ViewController and implement the datasource and delegate
  • Full Screen Browser: Tap on an image in the PhotoView to launch the full screen browser.
  • Swipe Gestures: Close the full screen browser by tapping the close button, tapping the image, or swiping up.
  • Swift: This project was writen completely in Swift.

Swift Version

For using swift version 3.0, tags 0.2.*
For using swift version 2.3, tags 0.1.*

Setup

To get started, install the JanePhotoBrowser either using Cocoapods or by adding the files in the Class folder into your project.

Add a PhotoBrowserView either in the Storyboard or programmatically by calling one of the initializers and set the datasource and delegate.

@IBOutlet weak var photoView:PhotoBrowserView?

override func viewDidLoad() {
	super.viewDidLoad
	
	self.photoView.dataSource = self
	self.photoView.delegate = self
}

If your delegate is a UIViewController, then the default implementation of the delegate methods is done for you in the PhotoBrowserDelegate protocol extension.

Data Source

The data source protocol supplies methods for the PhotoBrowser to get the images that need to be included.

Data Source Protocol:

public protocol PhotoBrowserDataSource:class {
    func photoBrowser(photoBrowser:PhotoBrowserView, photoAtIndex index: Int, forCell cell:PhotoBrowserViewCell) -> UIImage
    func numberOfPhotos(photoBrowser:PhotoBrowserView) -> Int
}

The numberOfPhotos method lets the photo browser know how many photos to expect. This is similar to the UITableViewDataSource and UICollectionViewDataSource methods.

photoBrowser(photoBrowser:PhotoBrowserView, photoAtIndex index: Int, forCell cell:PhotoBrowserViewCell) -> UIImage returns an UIImage for a given index. If you already have a list of images, you will just return them in this method. If you have to pull the image from a resource online, you may want to do something like the following:

func photoBrowser(photoBrowser: PhotoBrowserView, photoAtIndex index: Int, forCell cell:PhotoBrowserViewCell) -> UIImage {
    guard let URL = self.deal?.allImageUrls()[index] else { return UIImage() }
    
    var returnImage: UIImage = self.loadingImage
    
    //Get image from cache or online if not cached.  
    //Note that Image caching is not included in the project.
    MyImageCacheClass.image(atURL: URL) { (image) in
    	 //If the image was fetched online, this method may have already 
    	 //returned the loading image, so set the image on the 
    	 //photoBrowserViewCell as well as setting the returnImage.
        cell.imageView.image = image
        returnImage = image
    }
    return returnImage
}

License

This project is made available with the MIT License.

Feedback

If you have any issues or feature request for this project, please create an issue and/or send us a pull request.

We hope you enjoy the JanePhotoBrowser!

janephotobrowser's People

Contributors

barlowtucker avatar gordontucker avatar mikeandike avatar viktorsemenyuk 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.