Skip to content

Commit 6843974

Browse files
committed
Update the readme about SVGKit migration
1 parent 6785b5b commit 6843974

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

README.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99

1010
## 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).
1212

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).
1414

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
1616

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

1923
## Example
2024

@@ -24,9 +28,10 @@ You can modify the code or use some other SVG files to check the compatibility.
2428

2529
## Requirements
2630

27-
+ iOS 8
28-
+ tvOS 9
29-
+ macOS 10.10
31+
+ iOS 13+
32+
+ tvOS 13+
33+
+ macOS 10.15+
34+
+ watchOS 6+
3035

3136
## Installation
3237

@@ -53,80 +58,75 @@ SDWebImageSVGCoder is available through [Carthage](https://github.com/Carthage/C
5358
github "SDWebImage/SDWebImageSVGCoder"
5459
```
5560

61+
#### Swift Package Manager
62+
63+
SDWebImageSVGCoder is available through [Swift Package Manager](https://swift.org/package-manager).
64+
65+
```swift
66+
let package = Package(
67+
dependencies: [
68+
.package(url: "https://github.com/SDWebImage/SDWebImageSVGCoder.git", from: "1.0")
69+
]
70+
)
71+
```
72+
5673
## Usage
5774

58-
### Use UIImageView (render SVG as bitmap image)
75+
### Use UIImageView
5976

60-
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.
6178

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

6481
+ Objective-C
6582

6683
```objectivec
84+
// register coder, on AppDelegate
6785
SDImageSVGCoder *SVGCoder = [SDImageSVGCoder sharedCoder];
6886
[[SDImageCodersManager sharedManager] addCoder:SVGCoder];
87+
// load SVG url
6988
UIImageView *imageView;
70-
// this arg is optional, if don't provide, use the viewport size instead
71-
CGSize SVGImageSize = CGSizeMake(100, 100);
72-
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextSVGImageSize : @(SVGImageSize)];
89+
[imageView sd_setImageWithURL:url]
90+
// Changing size
91+
CGRect rect = imageView.frame;
92+
rect.size.width = 200;
93+
rect.size.height = 200;
94+
imageView.frame = rect;
7395
```
7496
7597
+ Swift
7698
7799
```swift
100+
// register coder, on AppDelegate
78101
let SVGCoder = SDImageSVGCoder.shared
79102
SDImageCodersManager.shared.addCoder(SVGCoder)
103+
// load SVG url
80104
let imageView: UIImageView
81105
imageView.sd_setImage(with: url)
82-
// this arg is optional, if don't provide, use the viewport size instead
83-
let SVGImageSize = CGSize(width: 100, height: 100)
84-
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.svgImageSize : SVGImageSize])
106+
// Changing size
107+
var rect = imageView.frame
108+
rect.size.width = 200
109+
rect.size.height = 200
110+
imageView.frame = rect
85111
```
86112

87-
### 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`
101-
imageView.contentMode = UIViewContentModeScaleAspectFill;
102-
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.
114114

115115
## Export SVG data
116116

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

119119
+ Objective-C
120120

121121
```objectivec
122-
UIImage *image; // Image generated from SDWebImage framework, actually a `SDSVGImage` instance.
122+
UIImage *image = imageView.image; // Image generated by this coder plugin
123123
NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatSVG];
124124
```
125125
126126
+ Swift
127127
128128
```swift
129-
let image; // Image generated from SDWebImage framework, actually a `SDSVGImage` instance.
129+
let image = imageView.image // Image generated by this coder plugin
130130
let imageData = image.sd_imageData(as: .SVG)
131131
```
132132

0 commit comments

Comments
 (0)