Giter Club home page Giter Club logo

agrume's Introduction

Build Status Carthage compatible Version License Platform

Agrume

An iOS image viewer written in Swift with support for multiple images.

bloggif_56c29473a93fb

Requirements

  • Swift 3.0
  • iOS 8.0+
  • Xcode 8+

Installation

The easiest way is through CocoaPods. Simply add the dependency to your Podfile and then pod install:

pod 'Agrume', :git => 'https://github.com/JanGorman/Agrume.git'

Or Carthage. Add the dependency to your Cartfile and then carthage update:

github "JanGorman/Agrume"

How

There are multiple ways you can use the image viewer (and the included Example project shows them all).

For just a single image it's as easy as

Basic

import Agrume

@IBAction func openImage(_ sender: AnyObject) {
  if let image = UIImage(named: "") {
	let agrume = Agrume(image: image)
	agrume.showFrom(self)	
  }
}

You can also pass in an NSURL and Agrume will take care of the download for you.

Multiple Images

If you're displaying a UICollectionView and want to add support for zooming, you can also call Agrume with an array of either images or URLs.

let agrume = Agrume(images: images, startIndex: indexPath.row, backgroundBlurStyle: .light)
agrume.didScroll = { [unowned self] index in
  self.collectionView?.scrollToItem(at: IndexPath(row: index, section: 0),
                                    at: [],
                                    animated: false)
}
agrume.showFrom(self)

This shows a way of keeping the zoomed library and the one in the background synced.

Custom Download Handler

If you want to take control of downloading images (e.g. for caching), you can also set a download closure that calls back to Agrume to set the image. I can recommend MapleBacon.

import Agrume
import MapleBacon

@IBAction func openURL(_ sender: AnyObject) {
  let agrume = Agrume(imageUrl: URL(string: "https://dl.dropboxusercontent.com/u/512759/MapleBacon.png")!, backgroundBlurStyle: .light)
	agrume.download = { url, completion in
	  ImageDownloader.downloadImage(url) { image in
		if let image = image {
		  completion(image)
		} else {
		  completion(nil)
		}
	}
  }
  agrume.showFrom(self)
}

Global Custom Download Handler

Instead of having to define a handler on a per instance basis you can instead set a handler on the AgrumeServiceLocator. Agrume will use this handler for all downloads unless overriden on an instance as described above:

import Agrume

AgrumeServiceLocator.shared.setDownloadHandler { url, completion in
  // Download data, cache it and remember to call the completion
}

// Some other place
agrume.showFrom(self)

Custom Data Source

For more dynamic library needs you can implement the AgrumeDataSource protocol that supplies images to Agrume. Agrume will query the data source for the number of images and if that number changes, reload it's scrolling image view.

import Agrume

let dataSource: AgrumeDataSource = MyDataSourceImplementation()
let agrume = Agrume(dataSource: dataSource)

agrume.showFrom(self)

Custom Background Snapshot

When showing the Agrume view controller, it'll default to taking a snapshot of the root view and blurring that. You can customize this behaviour by passing in a different view that it will blur and display:

let agrume = Agrume(image: image)
agrume.showFrom(self, backgroundSnapshotVC: self)

Status Bar Appearance

You can customize the status bar appearance when displaying the zoomed in view. Agrume has a statusBarStyle property:

let agrume = Agrume(image: image)
agrume.statusBarStyle = .lightContent
agrume.showFrom(self)

Licence

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

agrume's People

Contributors

arneson avatar broadwaylamb avatar cryptohashtags avatar dg0bab avatar hyouuu avatar jakecraige avatar jangorman avatar jonasfranz avatar jpodcedensek avatar lfarah avatar mcrakhman avatar orta avatar vkozlovskyi 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.