-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolygonView.m
44 lines (33 loc) · 919 Bytes
/
PolygonView.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
//
// PolygonView.m
// GraceWorld
//
// Created by John Detloff on 5/1/13.
// Copyright (c) 2013 Uebie. All rights reserved.
//
#import "PolygonView.h"
@implementation PolygonView {
NSArray *_points;
}
- (id)initWithFrame:(CGRect)frame points:(NSArray *)points {
self = [super initWithFrame:frame];
if (self) {
_points = points;
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, _color.CGColor);
UIBezierPath* path = [UIBezierPath bezierPath];
path.lineWidth = 4;
CGPoint firstPoint = [_points[0] CGPointValue];
[path moveToPoint:firstPoint];
for (int i = 1; i < [_points count]; i++) {
CGPoint point = [_points[i] CGPointValue];
[path addLineToPoint:point];
}
[path addLineToPoint:firstPoint];
[path fill];
}
@end