forked from Boris-Em/BEMCheckBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBEMPathManager.m
80 lines (64 loc) · 2.97 KB
/
BEMPathManager.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
//
// BEMPathManager.m
// CheckBox
//
// Created by Bobo on 9/19/15.
// Copyright (c) 2015 Boris Emorine. All rights reserved.
//
#import "BEMPathManager.h"
@implementation BEMPathManager
#pragma mark Paths
- (UIBezierPath *)pathForBox {
UIBezierPath* path;
switch (self.boxType) {
case BEMBoxTypeSquare:
path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.size, self.size) cornerRadius:3.0];
[path applyTransform:CGAffineTransformRotate(CGAffineTransformIdentity, M_PI * 2.5)];
[path applyTransform:CGAffineTransformMakeTranslation(self.size, 0)];
break;
default: {
CGFloat radius = self.size / 2;
path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.size / 2, self.size / 2)
radius: radius
startAngle: - M_PI / 4
endAngle: 2 * M_PI - M_PI / 4
clockwise:YES];
}
break;
}
return path;
}
- (UIBezierPath *)pathForCheckMark {
UIBezierPath* checkMarkPath = [UIBezierPath bezierPath];
[checkMarkPath moveToPoint: CGPointMake(self.size/3.1578, self.size/2)];
[checkMarkPath addLineToPoint: CGPointMake(self.size/2.0618, self.size/1.57894)];
[checkMarkPath addLineToPoint: CGPointMake(self.size/1.3953, self.size/2.7272)];
if (self.boxType == BEMBoxTypeSquare) {
// If we use a square box, the check mark should be a little bit bigger
[checkMarkPath applyTransform:CGAffineTransformMakeScale(1.5, 1.5)];
[checkMarkPath applyTransform:CGAffineTransformMakeTranslation(-self.size/4, -self.size/4)];
}
return checkMarkPath;
}
- (UIBezierPath *)pathForLongCheckMark {
UIBezierPath* checkMarkPath = [UIBezierPath bezierPath];
[checkMarkPath moveToPoint: CGPointMake(self.size/3.1578, self.size/2)];
[checkMarkPath addLineToPoint: CGPointMake(self.size/2.0618, self.size/1.57894)];
if (self.boxType == BEMBoxTypeSquare) {
// If we use a square box, the check mark should be a little bit bigger
[checkMarkPath addLineToPoint: CGPointMake(self.size/1.2053, self.size/4.5272)];
[checkMarkPath applyTransform:CGAffineTransformMakeScale(1.5, 1.5)];
[checkMarkPath applyTransform:CGAffineTransformMakeTranslation(-self.size/4, -self.size/4)];
} else {
[checkMarkPath addLineToPoint: CGPointMake(self.size/1.1553, self.size/5.9272)];
}
return checkMarkPath;
}
- (UIBezierPath *)pathForFlatCheckMark {
UIBezierPath* flatCheckMarkPath = [UIBezierPath bezierPath];
[flatCheckMarkPath moveToPoint: CGPointMake(self.size/4, self.size/2)];
[flatCheckMarkPath addLineToPoint: CGPointMake(self.size/2, self.size/2)];
[flatCheckMarkPath addLineToPoint: CGPointMake(self.size/1.2, self.size/2)];
return flatCheckMarkPath;
}
@end