/Optik

A Swift library for displaying images from any source, local or remote.

Primary LanguageSwiftMIT LicenseMIT

Optik

Travis build status Cocoapods Compatible Platform Docs

Description

Optik provides a simple viewing experience for a set of images, whether stored locally or remotely.

Requirements

  • iOS 9.0+
  • Xcode 8.1 or later

Installation

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

pod "Optik"

Usage

Optik can be used to display images stored either locally or remotely.

Displaying Images

Local Images

Local images can be displayed by creating an image viewer with an array of images:

let imageViewer = Optik.imageViewer(
    withImages: [
		UIImage(named: "image1.jpg")!,
		UIImage(named: "image2.jpg")!,
		UIImage(named: "image3.jpg")!
    ]
)

presentViewController(imageViewer, animated: true, completion: nil)

Remote Images

For remote images, an array of NSURLs should be provided - as well as an object conforming to the ImageDownloader protocol:

let imageDownloader = MyImageDownloader()

let imageViewer = Optik.imageViewer(
    withURLs: [
        NSURL(string: "https://somewebsite.com/image1.png")!,
        NSURL(string: "https://somewebsite.com/image2.png")!,
        NSURL(string: "https://somewebsite.com/image3.png")!
    ],
    imageDownloader: imageDownloader
)

presentViewController(imageViewer, animated: true, completion: nil)

Customizing the Image Viewer

Dismiss Button

The dismiss button image and position can be customized.

To indicate a custom dismiss button image, provide a dismissButtonImage parameter when creating an image viewer:

let imageViewer = Optik.imageViewer(
    withImages: [
        UIImage(named: "image1.jpg")!
    ],
    dismissButtonImage: UIImage(named: "MyDismissButton")
)

To indicate a position for the dismiss button, provide a dismissButtonPosition

let imageViewer = Optik.imageViewer(
    withImages: [
        UIImage(named: "image1.jpg")!
    ],
    dismissButtonImage: UIImage(named: "MyDismissButton"),
    dismissButtonPosition: .TopTrailing
)

Activity Indicator

When fetching remote images, an activity indicator is displayed while images are loaded. To indicate a custom activity indicator color, provide an activityIndicatorColor: parameter when creating an image viewer:

let imageViewer = Optik.imageViewer(
    withURLs: [
    	NSURL(string: "https://somewebsite.com/image1.png")!
    ],
    imageDownloader: imageDownloader,
    activityIndicatorColor: UIColor.redColor()
)

Contributing to Optik

To report a bug or enhancement request, feel free to file an issue under the respective heading.

If you wish to contribute to the project, fork this repo and submit a pull request. Code contributions should follow the standards specified in the Prolific Swift Style Guide.

License

prolific

Copyright (c) 2017 Prolific Interactive

Marker is maintained and sponsored by Prolific Interactive. It may be redistributed under the terms specified in the LICENSE file.