-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCross.m
63 lines (53 loc) · 1.88 KB
/
Cross.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
59
60
61
62
63
//
// Cross.m
// test
//
// Created by Satbir Tanda on 12/4/15.
// Copyright © 2015 Satbir Tanda. All rights reserved.
//
#import "Cross.h"
@implementation Cross
- (UIColor *)crossColor
{
if (!_crossColor) {
_crossColor = [UIColor yellowColor];
}
return _crossColor;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
UIBezierPath *crossPath = [UIBezierPath bezierPath];
crossPath.lineWidth = 0;
[self.crossColor setFill];
CGFloat midX = CGRectGetMidX(rect);
CGFloat maxX = CGRectGetMaxX(rect);
CGFloat midY = CGRectGetMidY(rect);
CGFloat quarterY = midY/2.0;
CGFloat maxY = CGRectGetMaxY(rect);
CGFloat offset = rect.size.width/10.0;
[crossPath moveToPoint:CGPointMake(midX - offset, 0)];
[crossPath addLineToPoint:CGPointMake(midX - offset, quarterY - offset)];
[crossPath addLineToPoint:CGPointMake(0, quarterY - offset)];
[crossPath addLineToPoint:CGPointMake(0, quarterY + offset)];
[crossPath addLineToPoint:CGPointMake(midX - offset, quarterY + offset)];
[crossPath addLineToPoint:CGPointMake(midX - offset, maxY)];
[crossPath addLineToPoint:CGPointMake(midX + offset, maxY)];
[crossPath addLineToPoint:CGPointMake(midX + offset, quarterY + offset)];
[crossPath addLineToPoint:CGPointMake(maxX, quarterY + offset)];
[crossPath addLineToPoint:CGPointMake(maxX, quarterY - offset)];
[crossPath addLineToPoint:CGPointMake(midX + offset, quarterY - offset)];
[crossPath addLineToPoint:CGPointMake(midX + offset, 0)];
[crossPath closePath];
[crossPath fill];
[crossPath stroke];
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
@end