欢迎光临
我们一直在努力

【Swift】Vulcan

建站超值云服务器,限时71元/月

【Swift】Vulcan

项目介绍:

Vulcan

https://github.com/jinSasaki/Vulcan

Multi image downloader with priority in Swift
Swift多图片下载器

Features 功能

  • Very light
    1、轻量级

  • Multi image download with priority
    2、具有优先级的多图像下载

  • Caching images
    3、图片缓存

  • Pure Swift
    4、纯Swift开发

  • Composable image
    5、可组合图像

  • Support webp

  • Now supported by Carthage only. See SwiftWebP.

Single download Multi download with priority
demo_01 demo_02

Installation

CocoaPods

Setup CocoaPods:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build Vulcan

Podfile

platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
pod 'Vulcan'
end

Then, run the following command:

$ pod install

Carthage

Setup carthage:

$ brew update
$ brew install carthage

Cartfile

github "jinSasaki/Vulcan"

Usage

Image downloading and show

import Vulcan

// Single downloading
imageView.vl_setImage(url: URL(string: "/path/to/image")!)

// Multi downloading
// This image will be overridden by the image of higher priority URL.
imageView.vl_setImage(urls: [
    .url(URL(string: "/path/to/image")!, priority: 100),
    .url(URL(string: "/path/to/image")!, priority: 1000)
    ])

WebP image

Add SwiftWebP.framework.

import Vulcan
import SwiftWebP

extension WebPDecoder: ImageDecoder {
    public func decode(data: Data, response: HTTPURLResponse, options: ImageDecodeOptions?) throws -> Image {
        let contentTypes = response.allHeaderFields.filter({ ($0.key as? String ?? "").lowercased() == "content-type" })
        guard
            let contentType = contentTypes.first,
            let value = contentType.value as? String,
            value == "image/webp",
            let image = WebPDecoder.decode(data) else {
                return try DefaultImageDecoder().decode(data: data, response: response, options: options)
        }
        return image
    }
}

// Set decoder to shared ImageDownloader
UIImageView.vl_sharedImageDownloader.decoder = WebPDecoder()

// Request image with URL
imageView.vl_setImage(url: URL(string: "/path/to/image")!)

Requirements 环境需求

  • iOS 8.0+

  • Xcode 8.1+

  • Swift 3.0.1+

code4app

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 【Swift】Vulcan
分享到: 更多 (0)