Skip to content

A lemony fresh iOS image viewer written in Swift.

License

Notifications You must be signed in to change notification settings

vkozlovskyi/Agrume

 
 

Repository files navigation

Carthage compatible Version License Platform

Agrume

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

bloggif_56c29473a93fb

Requirements

  • Swift 2.2
  • iOS 8.0+
  • Xcode 7+

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

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.

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?.scrollToItemAtIndexPath(NSIndexPath(forRow: index, inSection: 0),
    											atScrollPosition: .allZeros,
									            animated: false)
}
agrume.showFrom(self)

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

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: NSURL(string: "https://dl.dropboxusercontent.com/u/512759/MapleBacon.png")!, backgroundBlurStyle: .Light)
	agrume.download = { url, completion in
	  let manager = ImageManager.sharedManager
	  manager.downloadImageAtURL(url) { imageInstance, error in
		if error == nil {
		  completion(image: imageInstance.image)
		} else {
		  completion(image: nil)
		}
	}
  }
  agrume.showFrom(self)
}

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)

Licence

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

About

A lemony fresh iOS image viewer written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.4%
  • Ruby 1.7%
  • Objective-C 0.9%