Skip to content

Commit e155957

Browse files
committed
Update the readme and screenshot about detailed usage
1 parent 9412e94 commit e155957

File tree

10 files changed

+57
-10
lines changed

10 files changed

+57
-10
lines changed

Example/Screenshot/SVGDemo.png

-52.4 KB
Loading

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,48 @@
55
[![License](https://img.shields.io/cocoapods/l/SDWebImageSVGCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGCoder)
66
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageSVGCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSVGCoder)
77

8+
## What's for
9+
SDWebImageSVGCoder is a SVG coder plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the image loading support for [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) using [SVGKit](https://github.com/SVGKit/SVGKit) SVG engine.
10+
811
## Example
912

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

15+
You can modify the code or use some other SVG files to check the compatibility.
16+
1217
## Requirements
1318

19+
+ iOS 8
20+
1421
## Installation
1522

1623
SDWebImageSVGCoder is available through [CocoaPods](https://cocoapods.org). To install
1724
it, simply add the following line to your Podfile:
1825

1926
```ruby
2027
pod 'SDWebImageSVGCoder'
28+
pod 'SVGKit', :git => 'https://github.com/SVGKit/SVGKit.git', :branch => '2.x'
2129
```
2230

31+
**Note:** Because the dependency third party library [SVGKit](https://github.com/SVGKit/SVGKit#versions) does not release the 2.x version, and the current latest release version is not compatible for Xcode 9/10. So you should specify `2.x` branch dependency or using commit-id to import the dependency through CocoaPods.
32+
2333
## Usage
2434

35+
### Use UIImageView (render SVG as bitmap image)
36+
2537
To use SVG coder, you should firstly add the `SDImageSVGCoder` to the coders manager. Then you can call the View Category method to start load SVG images.
2638

39+
Because SVG is a [vector image](https://en.wikipedia.org/wiki/Vector_graphics) format, which means it does not have a fixed bitmap size. However, `UIImage` or `CGImage` are all [bitmap image](https://en.wikipedia.org/wiki/Raster_graphics). 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 `vectorImageSize` context option.
40+
2741
+ Objective-C
2842

29-
```objective-c
43+
```objectivec
3044
SDImageSVGCoder *SVGCoder = [SDImageSVGCoder sharedCoder];
3145
[[SDImageCodersManager sharedManager] addCoder:SVGCoder];
3246
UIImageView *imageView;
33-
[imageView sd_setImageWithURL:url];
47+
// this arg is optional, if don't provide, use the viewport size instead
48+
CGSize vectorImageSize = CGSizeMake(100, 100);
49+
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextVectorImageSize : @(vectorImageSize)];
3450
```
3551
3652
+ Swift
@@ -40,6 +56,37 @@ let SVGCoder = SDImageSVGCoder.shared
4056
SDImageCodersManager.shared.addCoder(SVGCoder)
4157
let imageView: UIImageView
4258
imageView.sd_setImage(with: url)
59+
// this arg is optional, if don't provide, use the viewport size instead
60+
let vectorImageSize = CGSize(width: 100, height: 100)
61+
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.vectorImageSize : vectorImageSize])
62+
```
63+
64+
### Use SVGKImageView (render SVG as vector image)
65+
66+
[SVGKit](https://github.com/SVGKit/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`.
67+
68+
For the documentation about `SVGKLayeredImageView`, `SVGKFastImageView` or `SVGKImageView`, check [SVGKit](https://github.com/SVGKit/SVGKit) repo for more information.
69+
70+
**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](https://github.com/rs/SDWebImage/wiki/Advanced-Usage#customization) feature of SDWebImage.
71+
72+
**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.
73+
74+
+ Objective-C
75+
76+
```objectivec
77+
SVGKImageView *imageView; // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
78+
imageView.contentMode = UIViewContentModeScaleAspectFill;
79+
imageView.sd_adjustContentMode = YES; // make `contentMode` works
80+
[imageView sd_setImageWithURL:url];
81+
```
82+
83+
+ Swift:
84+
85+
```swift
86+
let imageView: SVGKImageView // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
87+
imageView.contentMode = .aspectFill
88+
imageView.sd_adjustContentMode = true // make `contentMode` works
89+
imageView.sd_setImage(with: url)
4390
```
4491

4592
## Screenshot

SDWebImageSVGCoder/Classes/SDImageSVGCoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDImageSVGCoder.h
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/9/27.
5+
// Created by DreamPiggy on 2018/9/27.
66
//
77

88
#import <SDWebImage/SDWebImage.h>

SDWebImageSVGCoder/Classes/SDImageSVGCoder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDImageSVGCoder.m
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/9/27.
5+
// Created by DreamPiggy on 2018/9/27.
66
//
77

88
#import "SDImageSVGCoder.h"

SDWebImageSVGCoder/Classes/SDSVGImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDSVGImage.h
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/10.
5+
// Created by DreamPiggy on 2018/10/10.
66
//
77

88
#import <SDWebImage/SDWebImage.h>

SDWebImageSVGCoder/Classes/SDSVGImage.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDSVGImage.m
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/10.
5+
// Created by DreamPiggy on 2018/10/10.
66
//
77

88
#import "SDSVGImage.h"

SDWebImageSVGCoder/Classes/SDWebImageSVGCoderDefine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDWebImageSVGCoderDefine.h
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/11.
5+
// Created by DreamPiggy on 2018/10/11.
66
//
77

88
#import <SDWebImage/SDWebImage.h>

SDWebImageSVGCoder/Classes/SDWebImageSVGCoderDefine.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SDWebImageSVGCoderDefine.m
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/11.
5+
// Created by DreamPiggy on 2018/10/11.
66
//
77

88
#import "SDWebImageSVGCoderDefine.h"

SDWebImageSVGCoder/Classes/SVGKImageView+WebCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SVGKImageView+WebCache.h
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/10.
5+
// Created by DreamPiggy on 2018/10/10.
66
//
77

88
#import <SVGKit/SVGKit.h>

SDWebImageSVGCoder/Classes/SVGKImageView+WebCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SVGKImageView+WebCache.m
33
// SDWebImageSVGCoder
44
//
5-
// Created by lizhuoli on 2018/10/10.
5+
// Created by DreamPiggy on 2018/10/10.
66
//
77

88
#import "SVGKImageView+WebCache.h"

0 commit comments

Comments
 (0)