@@ -33,13 +33,59 @@ class PaperButton: UIControl
33
33
super. init ( coder: aDecoder)
34
34
}
35
35
36
+ // MARK: - Instance methods
37
+
36
38
override func tintColorDidChange( ) {
37
39
let color = self . tintColor. cgColor
38
40
self . topLayer. backgroundColor = color
39
41
self . middleLayer. backgroundColor = color
40
42
self . bottomLayer. backgroundColor = color
41
43
}
42
44
45
+ // MARK: - Private instance methods
46
+
47
+ func setup( ) {
48
+ let height : CGFloat = 2
49
+ let width : CGFloat = self . bounds. width
50
+ let cornerRadius : CGFloat = 1
51
+ let color : CGColor = self . tintColor. cgColor
52
+
53
+ self . topLayer = CALayer ( )
54
+ self . topLayer. frame = CGRect ( x: 0 , y: self . bounds. minY, width: width, height: height)
55
+ self . topLayer. cornerRadius = cornerRadius
56
+ self . topLayer. backgroundColor = color
57
+
58
+ self . middleLayer = CALayer ( )
59
+ self . middleLayer. frame = CGRect ( x: 0 , y: self . bounds. midY - height/ 2 , width: width, height: height)
60
+ self . middleLayer. cornerRadius = cornerRadius
61
+ self . middleLayer. backgroundColor = color
62
+
63
+ self . bottomLayer = CALayer ( )
64
+ self . bottomLayer. frame = CGRect ( x: 0 , y: self . bounds. maxY - height, width: width, height: height)
65
+ self . bottomLayer. cornerRadius = cornerRadius
66
+ self . bottomLayer. backgroundColor = color
67
+
68
+ self . layer. addSublayer ( self . topLayer)
69
+ self . layer. addSublayer ( self . middleLayer)
70
+ self . layer. addSublayer ( self . bottomLayer)
71
+
72
+ self . addTarget ( self , action: #selector( touchUpInsideHandler) , for: . touchUpInside)
73
+ }
74
+
75
+ // MARK: - Event handlers
76
+
77
+ @objc func touchUpInsideHandler( _ sender: PaperButton ) {
78
+ if ( self . showMenu) {
79
+ self . animateToMenu ( )
80
+ } else {
81
+ self . animateToClose ( )
82
+ }
83
+
84
+ self . showMenu = !self . showMenu
85
+ }
86
+
87
+ // MARK: - Animations
88
+
43
89
func animateToMenu( ) {
44
90
self . removeAllAnimations ( )
45
91
@@ -112,44 +158,6 @@ class PaperButton: UIControl
112
158
}
113
159
}
114
160
115
- func setup( ) {
116
- let height : CGFloat = 2
117
- let width : CGFloat = self . bounds. width
118
- let cornerRadius : CGFloat = 1
119
- let color : CGColor = self . tintColor. cgColor
120
-
121
- self . topLayer = CALayer ( )
122
- self . topLayer. frame = CGRect ( x: 0 , y: self . bounds. minY, width: width, height: height)
123
- self . topLayer. cornerRadius = cornerRadius
124
- self . topLayer. backgroundColor = color
125
-
126
- self . middleLayer = CALayer ( )
127
- self . middleLayer. frame = CGRect ( x: 0 , y: self . bounds. midY - height/ 2 , width: width, height: height)
128
- self . middleLayer. cornerRadius = cornerRadius
129
- self . middleLayer. backgroundColor = color
130
-
131
- self . bottomLayer = CALayer ( )
132
- self . bottomLayer. frame = CGRect ( x: 0 , y: self . bounds. maxY - height, width: width, height: height)
133
- self . bottomLayer. cornerRadius = cornerRadius
134
- self . bottomLayer. backgroundColor = color
135
-
136
- self . layer. addSublayer ( self . topLayer)
137
- self . layer. addSublayer ( self . middleLayer)
138
- self . layer. addSublayer ( self . bottomLayer)
139
-
140
- self . addTarget ( self , action: #selector( touchUpInsideHandler) , for: . touchUpInside)
141
- }
142
-
143
- @objc func touchUpInsideHandler( _ sender: PaperButton ) {
144
- if ( self . showMenu) {
145
- self . animateToMenu ( )
146
- } else {
147
- self . animateToClose ( )
148
- }
149
-
150
- self . showMenu = !self . showMenu
151
- }
152
-
153
161
func removeAllAnimations( ) {
154
162
self . topLayer. pop_removeAllAnimations ( )
155
163
self . middleLayer. pop_removeAllAnimations ( )
0 commit comments