Code Monkey home page Code Monkey logo

photobrowser's Introduction

Features

A simple photo browser to display remote photos. Kingfisher is used to download and cache images. Support:

  • Double-tap to zoom out & zoom in
  • Device rotation
  • Full screen mode
  • Long press action
  • Custom toolbar

Installation

Carthage

To integrate PhotoBrowser into your Xcode project using Carthage, specify it in your Cartfile:

$ github "teambition/PhotoBrowser"

Then, run the following command to build the PhotoBrowser framework:

$ carthage update

If Kingfisher is not used in your project, you have to drag it your self into your project from the [Carthage/Build] folder.

Run Demo

$ git clone https://github.com/teambition/PhotoBrowser.git

And then

$ carthage update

Usage

import PhotoBrowser

let photoBrowser = PhotoBrowser

let photo = Photo.init(image: nil, thumbnailImage: thumbnail1, photoUrl: photoUrl1)
let photo2 = Photo.init(image: nil, thumbnailImage: thumbnail2, photoUrl: photoUrl2)
let photo3 = Photo.init(image: nil, thumbnailImage: thumbnail3, photoUrl: photoUrl3)

photoBrowser.photos = [photo, photo2, photo3]

Set toolbarItems property of UIViewController to custom toolbar:

let item1 = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: nil)
item1.tintColor = UIColor.blackColor()
photoBrowser.toolbarItem = [item1]

When no item specified, toolbar will hide itself.

Implement PhotoBrowserDelegate to receive images long press gesture:

photoBrowser.photoBrowserDelegate = self

func longPressOn(photo: Photo, gesture: UILongPressGestureRecognizer) {
        guard let imageView = gesture.view as? UIImageView else {
            return
        }
        let alertController = UIAlertController.init(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
        let cancelAction = UIAlertAction.init(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
        let saveAction = UIAlertAction.init(title: "Save", style: UIAlertActionStyle.Default) {[unowned self] (action) -> Void in
            if let image = imageView.image {
                self.saveToAlbum(image)
            }
        }
        alertController.addAction(saveAction)
        alertController.addAction(cancelAction)
        self.photoBrowser?.presentViewController(alertController, animated: true, completion: nil)
    }

To-Do

  • Support datasource to provide data
  • Support Block-syntax for long press gesture

License

PhotoBrowser is released under the MIT license. See LICENSE for details.

photobrowser's People

Contributors

d-wang avatar hongxinhope avatar horexc avatar medisean avatar stormxx avatar

Stargazers

 avatar

Watchers

 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.