-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSPChainBonusAlertView.m
More file actions
76 lines (56 loc) · 2.04 KB
/
SPChainBonusAlertView.m
File metadata and controls
76 lines (56 loc) · 2.04 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
//
// SPChainBonusAlertView.m
// TextBlock
//
// Created by Fredrik Josefsson on 2011-08-28.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "SPChainBonusAlertView.h"
#import "SvgToBezier.h"
#import "SPCommon.h"
@implementation SPChainBonusAlertView
@synthesize bezierPath;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// sizes and positions
[self setBackgroundColor:[UIColor clearColor]];
CGPoint centerPoint = CGPointMake(frame.size.width * 0.5, frame.size.height * 0.5);
// ••• icon •••
// draw icon
[self addSvgPathIcon:kChainIconSVG];
// set icon scale to fit frame
float scale = frame.size.width / bezierPath.bounds.size.width;
// scale the path
CGAffineTransform transformScale;
transformScale = CGAffineTransformMakeScale(scale, scale);
[bezierPath applyTransform:transformScale];
// move the path
CGAffineTransform transformTranslate;
transformTranslate = CGAffineTransformMakeTranslation(centerPoint.x - bezierPath.bounds.size.width * 0.5, centerPoint.y - bezierPath.bounds.size.height * 0.5);
[bezierPath applyTransform:transformTranslate];
}
return self;
}
- (void) addSvgPathIcon:(NSString *)svgString {
// create svg vector symbol
SvgToBezier *bezierConverter = [[[SvgToBezier alloc] initFromSVGPathNodeDAttr:svgString inViewBoxSize:CGSizeMake(40.0, 40.0)] autorelease];
UIBezierPath *temp_bezierPath = [bezierConverter.bezier retain];
[self setBezierPath:temp_bezierPath];
[temp_bezierPath release];
// redraw
[self setNeedsDisplay];
}
- (void) drawRect:(CGRect)rect {
if(!bezierPath) return;
// get the current graphics context
CGContextRef ctx = UIGraphicsGetCurrentContext();
// set the drawing color
const float* col = CGColorGetComponents( [[SPCommon SPGetOffWhite] CGColor] );
CGContextSetRGBFillColor(ctx, col[0], col[1], col[2], 1.0);
// draw the path
CGContextAddPath(ctx, bezierPath.CGPath);
CGContextFillPath(ctx);
}
@end