forked from fjolnir/SVGPathSerializing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVGImageView.m
58 lines (52 loc) · 1.24 KB
/
SVGImageView.m
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
#import "SVGImageView.h"
#import "SVGLayer.h"
#import "SVGPortability.h"
@implementation SVGImageView
#if TARGET_OS_IPHONE
+ (Class)layerClass
{
return [SVGLayer class];
}
#else
- (CALayer *)makeBackingLayer
{
SVGLayer * const layer = [SVGLayer new];
layer.fillColor = _fillColor.CGColor;
layer.strokeColor = _strokeColor.CGColor;
if(_svgName)
[layer loadSVGFromFileNamed:_svgName];
else if(_svgSource)
layer.svgSource = _svgSource;
return layer;
}
- (BOOL)isFlipped
{
return YES;
}
- (void)sizeToFit
{
self.bounds = (NSRect) { self.bounds.origin, [self sizeThatFits:CGSizeZero] };
}
#endif
- (SVGLayer *)_svgLayer { return (id)self.layer; }
- (void)setsvgSource:(NSString * const)aSVG {
_svgSource = aSVG;
self._svgLayer.svgSource = aSVG;
}
- (void)setSvgName:(NSString * const)aName {
_svgName = aName;
[self._svgLayer loadSVGNamed:_svgName];
}
- (void)setFillColor:(SVGUI(Color) * const)aColor {
_fillColor = aColor;
self._svgLayer.fillColor = aColor.CGColor;
}
- (void)setStrokeColor:(SVGUI(Color) * const)aColor {
_strokeColor = aColor;
self._svgLayer.strokeColor = aColor.CGColor;
}
- (CGSize)sizeThatFits:(CGSize)aSize
{
return self.layer.preferredFrameSize;
}
@end