@@ -14,12 +14,39 @@ import UIKit
14
14
15
15
16
16
17
+ @available ( * , deprecated: 3.0 , message: " TKSimpleSwitchConfig is deprecated. " )
18
+ public struct TKSimpleSwitchConfig {
19
+ public var onColor : UIColor
20
+ public var offColor : UIColor
21
+ public var lineColor : UIColor
22
+ public var circleColor : UIColor
23
+ public var lineSize : Double
24
+
25
+
26
+
27
+ public init ( onColor : UIColor = UIColor ( red: 0.341 , green: 0.914 , blue: 0.506 , alpha: 1 ) ,
28
+ offColor : UIColor = UIColor ( white: 0.9 , alpha: 1 ) ,
29
+ lineColor : UIColor = UIColor ( white: 0.8 , alpha: 1 ) ,
30
+ circleColor : UIColor = UIColor . white,
31
+ lineSize : Double = 10 ) {
32
+ self . onColor = onColor
33
+ self . offColor = offColor
34
+ self . lineColor = lineColor
35
+ self . circleColor = circleColor
36
+ self . lineSize = lineSize
37
+
38
+
39
+ }
40
+
41
+ }
42
+
43
+
17
44
18
45
@IBDesignable
19
46
open class TKSimpleSwitch : TKBaseSwitch {
20
47
21
- fileprivate var swichControl = CAShapeLayer ( )
22
- fileprivate var backgroundLayer = CAShapeLayer ( )
48
+ private var swichControl = CAShapeLayer ( )
49
+ private var backgroundLayer = CAShapeLayer ( )
23
50
24
51
// 是否加旋转特效
25
52
@IBInspectable open var rotateWhenValueChange : Bool = false
@@ -148,8 +175,40 @@ open class TKSimpleSwitch: TKBaseSwitch {
148
175
backgroundLayer. add ( backgroundFillColorAnim, forKey: " Color " )
149
176
}
150
177
151
- fileprivate func stateToFillColor( _ isOn: Bool ) -> CGColor {
178
+ private func stateToFillColor( _ isOn: Bool ) -> CGColor {
152
179
return isOn ? onColor. cgColor : offColor. cgColor
153
180
}
154
181
155
182
}
183
+
184
+
185
+ // MARK: - Deprecated
186
+ extension TKSimpleSwitch {
187
+ @available ( * , deprecated: 3.0 , message: " config is deprecated. Use onColor, offColor, lineColor, circleColor, lineSize instead " )
188
+ open var config : TKSimpleSwitchConfig {
189
+ set {
190
+ if newValue. onColor != onColor {
191
+ onColor = newValue. onColor
192
+ }
193
+ if newValue. offColor != offColor {
194
+ offColor = newValue. offColor
195
+ }
196
+ if newValue. lineColor != lineColor {
197
+ lineColor = newValue. lineColor
198
+ }
199
+ if newValue. circleColor != circleColor {
200
+ lineColor = newValue. lineColor
201
+ }
202
+ if newValue. lineSize != lineSize {
203
+ lineSize = newValue. lineSize
204
+ }
205
+ }
206
+ get {
207
+ return TKSimpleSwitchConfig ( onColor: onColor,
208
+ offColor: offColor,
209
+ lineColor: lineColor,
210
+ circleColor: circleColor,
211
+ lineSize: lineSize)
212
+ }
213
+ }
214
+ }
0 commit comments