Skip to content

Easily embed Unsplash photos in UIImageView. Using Unsplash Source API.

License

Notifications You must be signed in to change notification settings

adboco/UnsplashImageView

Repository files navigation

UnsplashImageView

Version License Platform Swift Version FOSSA Status

UnsplashImageView allows to display Unsplash photos in UIImageView and make transitions between images. It uses Unsplash Source API.

Requirements

  • Xcode 9.0+
  • iOS 8.0+

Installation

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

pod 'UnsplashImageView'

Usage

import UnsplashImageView

With default configuration

UnsplashConfig.default.query = .random(featured: true) // Query to Unsplash. Default is `.random(featured: false)`.
UnsplashConfig.default.size = CGSize(width: 600, height: 600) // Specifies the size of images. Default is `nil`.
UnsplashConfig.default.terms = ["fruit", "vegan"] // Search terms. Default is `nil`.
UnsplashConfig.default.mode = .gallery(interval: 10.0, transition: .fade(0.5)) // Image loading mode. Default is `single`.
UnsplashConfig.default.fixed = .none

Start getting images

let imageView = UIImageView()
// ...
imageView.unsplash.start()

Stop getting images (if gallery mode enabled)

imageView.unsplash.stop()

With custom configuration

var config = UnsplashConfig()

config.query = .randomFromUser(username: "ari_spada")
config.mode = .single(transition: .none)
config.fixed = .daily

imageView.unsplash.start(with: config)

Modes

  • single. Get a single image.
  • gallery. Get a new image every x seconds.

Queries

  • photo(id: String). Get a specific photo by id.
  • random(featured: Bool). Get a random photo from Unsplash. If featured is true, it gets it from curated collections.
  • randomFromUser(username: String). Get a random photo from a specific user.
  • randomFromUserLikes(username: String). Get a random photo from a user's likes.
  • randomFromCollection(id: String). Get a random photo from a specific collection.

Updates

  • none. Always request a new photo. Default value.
  • daily. Returns the same photo during a day for the same query.
  • weekly. Returns the same photo during a week for the same query.

Author

adboco@telefonica.net, Adrián Bouza Correa

License

UnsplashImageView is available under the MIT license. See the LICENSE file for more info.

FOSSA Status