Coder Social home page Coder Social logo

gdimage's Introduction

๐Ÿ–ผ GDImage

GDImage is a Swift library providing background image-loading capabilities.

Features

  • Asnychronous image downloading
  • Two-layer caching: memory and disk
  • UIImage extensions offered
  • Support for download cancellation
  • Support for jpeg and png images tested

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

CocoaPods

CocoaPods 1.1.0+ is required.

To integrate GDImage into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'GDImage', :git => 'https://github.com/spinach/GDImage', :tag => '1.0.6'
end

Then, run the following command:

$ pod install

Carthage

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

github "spinach/GDImage"

Run carthage update to build the framework and drag the built GDImage.framework into your Xcode project.

Usage

QuickStart

The simplest way to use GDImage is using UIImageView extension

import GDImage

imageView.setImage(withLink: "https://s3.amazonaws.com/dummy-images-guy/algolia-logo.jpg")

GDImage will download the image asynchronously, put it in the memory cache and disk cache, and then display it in imageView.

Demo

You can quickly try out the library by cloning this repo and opening GDImage.xcworkspace. Build the GDImage target, then run the Demo target.

UIImageView Extension Methods

  • func setImage(withUrl: URL)
  • func setImage(withLink: String)
  • func cancelImageDownload()

GDImage Methods

GDImage offers more customisation.

import GDImage

let gdImage = GDImage()
gdImage.setImage(ofImageView: imageView, withUrl: url)

The constructor lets you customise whether to use caching or not, the contentMode of the UIImageView and the activityIndicatorStyle shown while loading the image.

GDImage(useCacheStore:Bool = true, contentMode: UIViewContentMode = .scaleAspectFit, activityIndicatorStyle: UIActivityIndicatorViewStyle = .gray)

The methods for GDImage are similar to the ones of extensions of UIImageView

  • func setImage(ofImageView: UIImageView, withUrl: URL)
  • func setImage(ofImageView: UIImageView, withLink: String)
  • func cancelDownload(ofImageView: UIImageView)

Completion Handler

If you wish to do some task at the completion of an image download, or do error handling, you can use the optional argument completionHandler like this:

imageView.setImage(withUrl: url) { (image, error) in
    // use error to do error handling
    // use image to do something with the image
}

TODOs

  • Create workspace containing Demo and Library
  • Write to Store Asynchronously
  • Manutally test with more image formats
  • Add default ActivityIndicator while loading image
  • Support for Carthage
  • More cleanup, especially print statements
  • Handle error cases (when image cannot be found). Can offer an errorHandler in the method
  • Provide onCompleteHandler
  • Write some basic UTs
  • Write more in-depth UTs
  • Improve the Demo project
  • Prefetch image capabilities
  • Provide placeholer image capabilities
  • Submit public pod

License

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

gdimage's People

Contributors

spinach avatar

Stargazers

 avatar

Watchers

 avatar  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.