You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-46Lines changed: 46 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,17 @@
8
8
9
9
10
10
## What's for
11
-
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.
11
+
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).
12
12
13
-
## Note about SVG on iOS
13
+
The SVG rendering is done using Apple's framework CoreSVG.framework (introduced in iOS 13/macOS 10.15).
14
14
15
-
From iOS 13 and Xcode 11, Apple provide the built-in support for SVG. You can use Xcode Asset Catalog to import your SVG files the same as PDF. (Click `Keep Vector Data`)
15
+
## Note for SVGKit user
16
16
17
-
But however, the new SVG framework (`CoreSVG.framework`) is still in Private API. If you're interested in this, you can try to use [iOS13_SVG](https://github.com/SDWebImage/SDWebImageSVGCoder/tree/iOS13_SVG) branch. Which bring the built-in SVG support for `UIImageView` and vector rendering, without the relay on SVGKit.
17
+
Previously before 1.0.0 version, this SVG Coder is powered by third party library [SVGKit](https://github.com/SVGKit/SVGKit). Which support iOS 8+(macOS 10.10+) as well.
18
+
19
+
However, due to the lack support of that third party library, which contains massive issues without community's help, no clarity of version release, makes a pain for us to maintain. So, We decide to deprecate SVGKit support and move it into another repo: [SDWebImageSVGKitPlugin](https://github.com/SDWebImage/SDWebImageSVGKitPlugin).
20
+
21
+
User who use SVGKit or have to support iOS 8+ can still use that SVGKit plugin instead, you can also mix these two SVG coder at the same time. But since Apple already provide a built-in framework support. We prefer to use that as well, which can reduce complicated dependency, code size, and get polished from Apple's system upgrade.
18
22
19
23
## Example
20
24
@@ -24,9 +28,10 @@ You can modify the code or use some other SVG files to check the compatibility.
24
28
25
29
## Requirements
26
30
27
-
+ iOS 8
28
-
+ tvOS 9
29
-
+ macOS 10.10
31
+
+ iOS 13+
32
+
+ tvOS 13+
33
+
+ macOS 10.15+
34
+
+ watchOS 6+
30
35
31
36
## Installation
32
37
@@ -53,80 +58,75 @@ SDWebImageSVGCoder is available through [Carthage](https://github.com/Carthage/C
53
58
github "SDWebImage/SDWebImageSVGCoder"
54
59
```
55
60
61
+
#### Swift Package Manager
62
+
63
+
SDWebImageSVGCoder is available through [Swift Package Manager](https://swift.org/package-manager).
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.
77
+
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. See [Wiki - Coder Usage](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#coder-usage) here for these steps.
61
78
62
-
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 `SVGImageSize` context option. And you can specify whether or not to keep aspect ratio during scale using `SVGImagePreserveAspectRatio` context option.
79
+
Note SVG is a [vector image](https://en.wikipedia.org/wiki/Vector_graphics) format, and UIImageView/NSImageView support rendering vector image as well. Which means you can change the size without losing any details.
### Use SVGKImageView (render SVG as vector image)
88
-
89
-
[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`.
90
-
91
-
For the documentation about `SVGKLayeredImageView`, `SVGKFastImageView` or `SVGKImageView`, check [SVGKit](https://github.com/SVGKit/SVGKit) repo for more information.
92
-
93
-
**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.
94
-
95
-
**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.
96
-
97
-
+ Objective-C
98
-
99
-
```objectivec
100
-
SVGKImageView *imageView; // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
imageView.sd_adjustContentMode = YES; // make `contentMode` works
103
-
[imageView sd_setImageWithURL:url];
104
-
```
105
-
106
-
+ Swift:
107
-
108
-
```swift
109
-
let imageView: SVGKImageView // can be either `SVGKLayeredImageView` or `SVGKFastImageView`
110
-
imageView.contentMode = .aspectFill
111
-
imageView.sd_adjustContentMode = true // make `contentMode` works
112
-
imageView.sd_setImage(with: url)
113
-
```
113
+
Note since UIImageView/NSImageView support this vector rendering, it means this coder plugin can be compatible for [SwiftUI](https://developer.apple.com/xcode/swiftui/). Check [SDWebImageSwiftUI](https://github.com/SDWebImage/SDWebImageSwiftUI/issues/50) for usage.
114
114
115
115
## Export SVG data
116
116
117
-
`SDWebImageSVGCoder` provide an easy way to export the SVG image generated from framework, to the original SVG data.
117
+
`SDWebImageSVGCoder` provide an easy way to export the SVG image generated by this coder plugin, to the original SVG data.
118
118
119
119
+ Objective-C
120
120
121
121
```objectivec
122
-
UIImage *image; // Image generated from SDWebImage framework, actually a `SDSVGImage` instance.
122
+
UIImage *image = imageView.image; // Image generated by this coder plugin
0 commit comments