-
Notifications
You must be signed in to change notification settings - Fork 1
/
YinYang.m
84 lines (72 loc) · 2.33 KB
/
YinYang.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// YinYang.m
// test
//
// Created by Satbir Tanda on 12/12/15.
// Copyright © 2015 Satbir Tanda. All rights reserved.
//
#import "YinYang.h"
@implementation YinYang
#define DEGREES_TO_RADIANS(degrees) ((M_PI * degrees)/ 180.0)
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (UIColor *)yinColor
{
if (!_yinColor) {
_yinColor = [UIColor whiteColor];
}
return _yinColor;
}
- (UIColor *)yangColor
{
if (!_yangColor) {
_yangColor = [UIColor blackColor];
}
return _yangColor;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
UIBezierPath *yinPath = [UIBezierPath bezierPath];
CGFloat midX = CGRectGetMidX(rect);
CGFloat midY = CGRectGetMidY(rect);
CGFloat maxY = CGRectGetMaxY(rect);
CGFloat arcRadius = rect.size.width/2.0 - yinPath.lineWidth;
CGFloat arcStartAngle = DEGREES_TO_RADIANS(90);
CGFloat arcEndAngle = DEGREES_TO_RADIANS(270);
[self.yinColor setFill];
[yinPath addArcWithCenter:CGPointMake(midX, midY)
radius:arcRadius
startAngle:arcStartAngle
endAngle:arcEndAngle
clockwise:YES];
[yinPath addArcWithCenter:CGPointMake(midX, midY/2.0)
radius:arcRadius/2.0
startAngle:arcStartAngle
endAngle:arcEndAngle
clockwise:NO];
[yinPath addArcWithCenter:CGPointMake(midX, maxY*3.0/4.0)
radius:arcRadius/2.0
startAngle:-arcStartAngle
endAngle:arcStartAngle
clockwise:NO];
[yinPath closePath];
[yinPath stroke];
[yinPath fill];
UIBezierPath *yinCirclePath = [UIBezierPath bezierPath];
[self.yangColor setFill];
[yinCirclePath addArcWithCenter:CGPointMake(midX, midY/2.0)
radius:arcRadius/8.0
startAngle:DEGREES_TO_RADIANS(0)
endAngle:DEGREES_TO_RADIANS(360)
clockwise:YES];
[yinCirclePath closePath];
[yinCirclePath fill];
}
@end