forked from pocketsvg/PocketSVG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVGImageView.m
More file actions
111 lines (99 loc) · 2.73 KB
/
SVGImageView.m
File metadata and controls
111 lines (99 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* This file is part of the PocketSVG package.
* Copyright (c) Ponderwell, Ariel Elkin, Fjölnir Ásgeirsson, and Contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "SVGImageView.h"
#import "SVGLayer.h"
#import "SVGPortability.h"
@implementation SVGImageView {
SVGLayer *_svgLayer;
}
#if TARGET_OS_IPHONE
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
_svgLayer = (SVGLayer *)self.layer;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
_svgLayer = (SVGLayer *)self.layer;
}
return self;
}
#else
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
self.wantsLayer = YES;
_svgLayer = [SVGLayer new];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
self.wantsLayer = YES;
_svgLayer = [SVGLayer new];
}
return self;
}
#endif
- (instancetype)initWithSVGSource:(NSString *)svgSource {
if (self = [self init]) {
self.svgSource = svgSource;
}
return self;
}
- (instancetype)initWithContentsOfURL:(NSURL *)url {
if (self = [self init]) {
self.svgURL = url;
}
return self;
}
#if TARGET_OS_IPHONE
+ (Class)layerClass
{
return [SVGLayer class];
}
#else
- (CALayer *)makeBackingLayer
{
return _svgLayer;
}
- (BOOL)isFlipped
{
return YES;
}
- (void)sizeToFit
{
self.bounds = (NSRect) { self.bounds.origin, [self sizeThatFits:CGSizeZero] };
}
#endif
- (NSString *)svgName { return _svgLayer.svgName; }
- (void)setSvgName:(NSString * const)aFileName { _svgLayer.svgName = aFileName; }
- (void)setSvgSource:(NSString * const)aSVG { [_svgLayer setSvgSource:aSVG]; }
- (NSURL *)svgURL { return _svgLayer.svgURL; }
- (void)setSvgURL:(NSURL *)svgURL { _svgLayer.svgURL = svgURL; }
- (PSVGColor *)fillColor { return _svgLayer.fillColor
? [PSVGColor colorWithCGColor:_svgLayer.fillColor]
: nil; }
- (void)setFillColor:(PSVGColor * const)aColor { _svgLayer.fillColor = aColor.CGColor; }
- (PSVGColor *)strokeColor { return _svgLayer.strokeColor
? [PSVGColor colorWithCGColor:_svgLayer.strokeColor]
: nil; }
- (void)setStrokeColor:(PSVGColor * const)aColor { _svgLayer.strokeColor = aColor.CGColor; }
- (CGSize)sizeThatFits:(CGSize)aSize
{
return self.layer.preferredFrameSize;
}
- (CGSize)intrinsicContentSize
{
return [self sizeThatFits:CGSizeZero];
}
@end