8
8
9
9
#import " SDViewController.h"
10
10
#import < SDWebImageSVGCoder/SDWebImageSVGCoder.h>
11
- #import < SVGKit/SVGKit.h>
12
11
13
12
@interface SDViewController ()
14
13
@@ -23,26 +22,22 @@ - (void)viewDidLoad
23
22
24
23
SDImageSVGCoder *SVGCoder = [SDImageSVGCoder sharedCoder ];
25
24
[[SDImageCodersManager sharedManager ] addCoder: SVGCoder];
26
- NSURL *svgURL = [NSURL URLWithString: @" https://upload.wikimedia .org/wikipedia/commons/1/14/Mahuri .svg" ];
27
- NSURL *svgURL2 = [NSURL URLWithString: @" https://upload.wikimedia .org/wikipedia/commons/2/2d/Sample_SVG_file %2C _signature .svg" ];
25
+ NSURL *svgURL = [NSURL URLWithString: @" https://dev.w3 .org/SVG/tools/svgweb/samples/svg-files/w3c .svg" ];
26
+ NSURL *svgURL2 = [NSURL URLWithString: @" https://dev.w3 .org/SVG/tools/svgweb/samples/svg-files/wikimedia .svg" ];
28
27
NSURL *svgURL3 = [NSURL URLWithString: @" https://simpleicons.org/icons/github.svg" ];
29
28
30
29
CGSize screenSize = [UIScreen mainScreen ].bounds .size ;
31
30
32
- // `SVGKLayeredImageView`, best on performance and do actually vector image rendering (translate SVG to CALayer tree).
33
- SVGKImageView *imageView1 = [[SVGKLayeredImageView alloc ] initWithSVGKImage: nil ];
31
+ UIImageView *imageView1 = [[UIImageView alloc ] init ];
34
32
imageView1.frame = CGRectMake (0 , 0 , screenSize.width , screenSize.height / 2 );
35
- imageView1.sd_adjustContentMode = YES ; // make `contentMode` works
36
- imageView1.contentMode = UIViewContentModeScaleAspectFill;
37
- imageView1.clipsToBounds = YES ;
33
+ imageView1.contentMode = UIViewContentModeScaleAspectFit;
38
34
39
- // `SVGKFastImageView`, draw SVG as bitmap dynamically when size changed.
40
- SVGKImageView *imageView2 = [[SVGKFastImageView alloc ] initWithSVGKImage: nil ];
35
+ UIImageView *imageView2 = [[UIImageView alloc ] init ];
41
36
imageView2.frame = CGRectMake (0 , screenSize.height / 2 , screenSize.width , screenSize.height / 2 );
42
- imageView2.clipsToBounds = YES ;
37
+ imageView2.contentMode = UIViewContentModeScaleAspectFill ;
43
38
44
- // `UIImageView`, draw SVG as bitmap image with fixed size, like PNG.
45
39
UIImageView *imageView3 = [[UIImageView alloc ] initWithFrame: CGRectMake (screenSize.width - 100 , screenSize.height - 100 , 100 , 100 )];
40
+ imageView2.contentMode = UIViewContentModeScaleToFill;
46
41
47
42
[self .view addSubview: imageView1];
48
43
[self .view addSubview: imageView2];
@@ -60,10 +55,16 @@ - (void)viewDidLoad
60
55
NSLog (@" SVGKFastImageView SVG load success" );
61
56
}
62
57
}];
63
- // For `UIImageView`, you can specify a desired SVG size instead of original SVG viewport (which may be small)
64
- [imageView3 sd_setImageWithURL: svgURL3 placeholderImage: nil options: SDWebImageRetryFailed context: @{SDWebImageContextSVGImageSize : @(CGSizeMake (100 , 100 ))} progress: nil completed: ^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
58
+ [imageView3 sd_setImageWithURL: svgURL3 placeholderImage: nil options: SDWebImageRetryFailed context: nil progress: nil completed: ^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
65
59
if (image) {
66
- NSLog (@" UIImageView SVG load success" );
60
+ NSLog (@" SVG load animation success" );
61
+ [UIView animateWithDuration: 2 animations: ^{
62
+ imageView3.bounds = CGRectMake (0 , 0 , 300 , 300 );
63
+ } completion: ^(BOOL finished) {
64
+ [UIView animateWithDuration: 2 animations: ^{
65
+ imageView3.bounds = CGRectMake (0 , 0 , 100 , 100 );
66
+ }];
67
+ }];
67
68
}
68
69
}];
69
70
}
0 commit comments