All Projects → SDWebImage → SDWebImageSVGKitPlugin

SDWebImage / SDWebImageSVGKitPlugin

Licence: MIT license
A SDWebImage plugin to support SVG with SVGKit and category

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to SDWebImageSVGKitPlugin

SDWebImagePhotosPlugin
A SDWebImage plugin to support Photos framework image loading
Stars: ✭ 47 (+213.33%)
Mutual labels:  tvos, sdwebimage
SDWebImageHEIFCoder
A SDWebImage coder plugin to support HEIF image without Apple's Image/IO framework
Stars: ✭ 31 (+106.67%)
Mutual labels:  tvos, sdwebimage
ScaledFont
ScaledFont - Using custom fonts with dynamic type
Stars: ✭ 50 (+233.33%)
Mutual labels:  tvos
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (+73.33%)
Mutual labels:  tvos
xxHash-Swift
xxHash framework in Swift.
Stars: ✭ 22 (+46.67%)
Mutual labels:  tvos
fingerprintjs-pro-ios
Official iOS/tvOS agent & SDK for accurate device identification, created for the Fingerprint Pro identification API.
Stars: ✭ 35 (+133.33%)
Mutual labels:  tvos
articles-ko
Articles for NSHipster.co.kr
Stars: ✭ 18 (+20%)
Mutual labels:  tvos
Futures
Lightweight promises for iOS, macOS, tvOS, watchOS, and Linux
Stars: ✭ 59 (+293.33%)
Mutual labels:  tvos
SwiftKit
SwiftKit adds extra functionality to the Swift programming language.
Stars: ✭ 47 (+213.33%)
Mutual labels:  tvos
Orchard
Device identification in Swift and Objective-C for iOS, watchOS, and tvOS.
Stars: ✭ 15 (+0%)
Mutual labels:  tvos
SDWebImageYYPlugin
A SDWebImage plugin to integrate YYImage & YYCache for image rendering & caching
Stars: ✭ 21 (+40%)
Mutual labels:  sdwebimage
CompositionalLayoutDSL
CompositionalLayoutDSL, library to simplify the creation of UICollectionViewCompositionalLayout. It wraps the UIKit API and makes the code shorter and easier to read.
Stars: ✭ 47 (+213.33%)
Mutual labels:  tvos
xharness
C# command line tool for running tests on Android / iOS / tvOS devices and simulators
Stars: ✭ 123 (+720%)
Mutual labels:  tvos
WWDCNotes
WWDCNotes.com content
Stars: ✭ 343 (+2186.67%)
Mutual labels:  tvos
TvOSTextViewer
Light and scrollable view controller for tvOS to present blocks of text
Stars: ✭ 45 (+200%)
Mutual labels:  tvos
SkiaKit
Swift Bindings to the Skia 2D graphics Library
Stars: ✭ 95 (+533.33%)
Mutual labels:  tvos
Juicer
Juicer is a generic animation / motion library for macOS & iOS & tvOS written in Swift
Stars: ✭ 13 (-13.33%)
Mutual labels:  tvos
wwdc2018
You read my developer triceraptus migration notes from dub dub dc 2018
Stars: ✭ 48 (+220%)
Mutual labels:  tvos
Outlaw
JSON mapper for macOS, iOS, tvOS, and watchOS
Stars: ✭ 24 (+60%)
Mutual labels:  tvos
KinopubTV
Kinopub for tvOS
Stars: ✭ 18 (+20%)
Mutual labels:  tvos

SDWebImageSVGKitPlugin

CI Status Version License Platform Carthage compatible

Background

Currently SDWebImage org provide 3 kinds of SVG Coder Plugin support, here is comparison:

Plugin Name Vector Image Bitmap Image Platform Compatibility Dependency
SVGNativeCoder NO YES iOS 9+ Best and W3C standard adobe/svg-native-viewer
SVGCoder YES YES iOS 13+ OK but buggy on some SVG Apple CoreSVG(Private)
SVGKitPlugin YES NO iOS 9+ Worst, no longer maintain SVGKit/SVGKit

What's for

SDWebImageSVGKitPlugin is a SVG coder plugin for SDWebImage framework, which provide the image loading support for SVG using SVGKit SVG engine.

Note: iOS 13+/macOS 10.15+ supports native SVG rendering (called Symbol Image), with system framework to load SVG. Check SDWebImageSVGCoder for more information.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

You can modify the code or use some other SVG files to check the compatibility.

Requirements

  • iOS 9+
  • tvOS 9+
  • macOS 10.11+
  • Xcode 11+

Installation

CocoaPods

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

pod 'SDWebImageSVGKitPlugin'

Swift Package Manager (Xcode 11+)

SDWebImagePhotosPlugin is available through Swift Package Manager.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/SDWebImage/SDWebImageSVGKitPlugin.git", from: "1.4")
    ]
)

Carthage

SDWebImageSVGKitPlugin is available through Carthage.

github "SDWebImage/SDWebImageSVGKitPlugin"

Usage

Use UIImageView (render SVG as bitmap image)

To use SVG coder, you should firstly add the SDImageSVGKCoder to the coders manager. Then you can call the View Category method to start load SVG images.

Because SVG is a vector image format, which means it does not have a fixed bitmap size. However, UIImage or CGImage are all bitmap image. For UIImageView, we will only parse SVG with a fixed image size (from the SVG viewPort information). But we also support you to specify a desired size during image loading using SDWebImageContextThumbnailPixelSize context option. And you can specify whether or not to keep aspect ratio during scale using SDWebImageContextImagePreserveAspectRatio context option.

  • Objective-C
SDImageSVGKCoder *svgCoder = [SDImageSVGKCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:svgCoder];
UIImageView *imageView;
// this arg is optional, if don't provide, use the viewport size instead
CGSize svgImageSize = CGSizeMake(100, 100);
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize : @(svgImageSize)];
  • Swift
let svgCoder = SDImageSVGKCoder.shared
SDImageCodersManager.shared.addCoder(svgCoder)
let imageView: UIImageView
imageView.sd_setImage(with: url)
// this arg is optional, if don't provide, use the viewport size instead
let svgImageSize = CGSize(width: 100, height: 100)
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : svgImageSize])

Use SVGKImageView (render SVG as vector image)

SVGKit also provide some built-in image view class for vector image loading (scale to any size without losing detail). The SVGKLayeredImageView && SVGKFastImageView are the subclass of SVGKImageView base class. We supports these image view class as well. You can just use the same API like normal UIImageView.

For the documentation about SVGKLayeredImageView, SVGKFastImageView or SVGKImageView, check SVGKit repo for more information.

Note: If you only use these image view class and don't use SVG on UIImageView, you don't need to register the SVG coder to coders manager. These image view loading was using the Custom Image Class feature of SDWebImage.

Attention: These built-in image view class does not works well on UIView.contentMode property, you need to re-scale the layer tree after image was loaded. We provide a simple out-of-box solution to support it. Set the sd_adjustContentMode property to YES then all things done.

  • Objective-C
SVGKImageView *imageView; // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.sd_adjustContentMode = YES; // make `contentMode` works
[imageView sd_setImageWithURL:url];
  • Swift:
let imageView: SVGKImageView // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
imageView.contentMode = .aspectFill
imageView.sd_adjustContentMode = true // make `contentMode` works
imageView.sd_setImage(with: url)

Export SVG data

SDWebImageSVGKitPlugin provide an easy way to export the SVG image generated from framework, to the original SVG data.

  • Objective-C
UIImage *image; // Image generated from SDWebImage framework, actually a `SDSVGKImage` instance.
NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatSVG];
  • Swift
let image: UIImage // Image generated from SDWebImage framework, actually a `SDSVGKImage` instance.
let imageData = image.sd_imageData(as: .SVG)

Screenshot

These SVG images are from wikimedia, you can try the demo with your own SVG image as well.

Author

DreamPiggy

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].