|
2 | 2 |
|
3 | 3 | #import <QuartzCore/QuartzCore.h> |
4 | 4 |
|
| 5 | +#import "SVGKSourceString.h" |
| 6 | + |
5 | 7 | @interface SVGKLayeredImageView() |
6 | 8 | @property(nonatomic,retain) CAShapeLayer* internalBorderLayer; |
7 | 9 | @end |
@@ -41,17 +43,78 @@ - (id)initWithSVGKImage:(SVGKImage*) im |
41 | 43 | if( im == nil ) |
42 | 44 | { |
43 | 45 | NSLog(@"[%@] WARNING: you have initialized an [%@] with a blank image (nil). Possibly because you're using Storyboards or NIBs which Apple won't allow us to decorate. Make sure you assign an SVGKImage to the .image property!", [self class], [self class]); |
| 46 | + |
| 47 | +self = [super initWithFrame:CGRectMake(0,0,100,100)]; // coincides with the inline SVG below! |
| 48 | +if( self ) |
| 49 | +{ |
| 50 | +self.backgroundColor = [UIColor clearColor]; |
| 51 | + |
| 52 | +NSString* svgStringDefaultContents = @"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\ |
| 53 | +\ |
| 54 | +<svg\ |
| 55 | +xmlns:svg=\"http://www.w3.org/2000/svg\"\ |
| 56 | +xmlns=\"http://www.w3.org/2000/svg\"\ |
| 57 | +width=\"100\"\ |
| 58 | +height=\"100\"\ |
| 59 | +id=\"svg2\"\ |
| 60 | +version=\"1.1\"\ |
| 61 | +<defs\ |
| 62 | +id=\"defs4\" />\ |
| 63 | +<metadata\ |
| 64 | +id=\"metadata7\">\ |
| 65 | +</metadata>\ |
| 66 | +<g\ |
| 67 | +id=\"layer1\"\ |
| 68 | +transform=\"translate(0,-952.36218)\">\ |
| 69 | +<rect\ |
| 70 | +style=\"opacity:0.98000003999999996;color:#000000;fill:#bf01ff;fill-opacity:0.99607843;fill-rule:nonzero;stroke:none;stroke-width:3;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate\"\ |
| 71 | +id=\"rect2985\"\ |
| 72 | +width=\"100\"\ |
| 73 | +height=\"100\"\ |
| 74 | +x=\"0\"\ |
| 75 | +y=\"952.36218\" />\ |
| 76 | +<text\ |
| 77 | +xml:space=\"preserve\"\ |
| 78 | +style=\"font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#f6ff0f;fill-opacity:1;stroke:none;font-family:Sans\"\ |
| 79 | +x=\"6.3190379\"\ |
| 80 | +y=\"991.14648\"\ |
| 81 | +id=\"text3755\"\ |
| 82 | +><tspan\ |
| 83 | +x=\"6.3190379\"\ |
| 84 | +y=\"991.14648\"\ |
| 85 | +id=\"tspan3759\"\ |
| 86 | +style=\"font-size:24px;fill:#f6ff0f;fill-opacity:1\">Missing</tspan></text>\ |
| 87 | +<text\ |
| 88 | +xml:space=\"preserve\"\ |
| 89 | +style=\"font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#fffc45;fill-opacity:1;stroke:none;font-family:Sans\"\ |
| 90 | +x=\"26.460968\"\ |
| 91 | +y=\"1030.2456\"\ |
| 92 | +id=\"text3763\"\ |
| 93 | +><tspan\ |
| 94 | +id=\"tspan3765\"\ |
| 95 | +x=\"26.460968\"\ |
| 96 | +y=\"1030.2456\"\ |
| 97 | +style=\"font-size:24px;fill:#fffc45;fill-opacity:1\">SVG</tspan></text>\ |
| 98 | +</g>\ |
| 99 | +</svg>"; |
| 100 | + |
| 101 | +SVGKImage* defaultBlankImage = [SVGKImage imageWithSource:[SVGKSourceString sourceFromContentsOfString:svgStringDefaultContents]]; |
| 102 | + |
| 103 | +((SVGKLayer*) self.layer).SVGImage = defaultBlankImage; |
| 104 | +} |
44 | 105 | } |
45 | | - |
46 | | - self = [super init]; |
47 | | - if (self) |
| 106 | +else |
48 | 107 | { |
49 | | -self.frame = CGRectMake( 0,0, im.CALayerTree.frame.size.width, im.CALayerTree.frame.size.height ); // default: 0,0 to width x height of original image |
50 | | -self.backgroundColor = [UIColor clearColor]; |
51 | | - |
52 | | -((SVGKLayer*) self.layer).SVGImage = im; |
53 | | - |
54 | | - } |
| 108 | +self = [super initWithFrame:CGRectMake( 0,0, im.CALayerTree.frame.size.width, im.CALayerTree.frame.size.height )]; // default: 0,0 to width x height of original image]; |
| 109 | +if (self) |
| 110 | +{ |
| 111 | +self.backgroundColor = [UIColor clearColor]; |
| 112 | + |
| 113 | +((SVGKLayer*) self.layer).SVGImage = im; |
| 114 | + |
| 115 | +} |
| 116 | +} |
| 117 | + |
55 | 118 | return self; |
56 | 119 | } |
57 | 120 |
|
|
0 commit comments