@@ -224,7 +224,7 @@ public class M13Checkbox: UIControl {
224
224
225
225
/// The manager that manages display and animations of the checkbox.
226
226
/// The default animation is a stroke.
227
- fileprivate var manager : M13CheckboxController = M13CheckboxStrokeController ( )
227
+ fileprivate var controller : M13CheckboxController = M13CheckboxStrokeController ( )
228
228
229
229
//----------------------------
230
230
// MARK: - Initalization
@@ -243,11 +243,11 @@ public class M13Checkbox: UIControl {
243
243
/// The setup shared between initalizers.
244
244
fileprivate func sharedSetup( ) {
245
245
// Set up the inital state.
246
- for aLayer in manager . layersToDisplay {
246
+ for aLayer in controller . layersToDisplay {
247
247
layer. addSublayer ( aLayer)
248
248
}
249
- manager . tintColor = tintColor
250
- manager . resetLayersForState ( . unchecked)
249
+ controller . tintColor = tintColor
250
+ controller . resetLayersForState ( . unchecked)
251
251
252
252
let longPressGesture = M13CheckboxGestureRecognizer ( target: self , action: #selector( M13Checkbox . handleLongPress ( _: ) ) )
253
253
addGestureRecognizer ( longPressGesture)
@@ -289,7 +289,7 @@ public class M13Checkbox: UIControl {
289
289
/// The current state of the checkbox.
290
290
public var checkState : CheckState {
291
291
get {
292
- return manager . state
292
+ return controller . state
293
293
}
294
294
set {
295
295
setCheckState ( newValue, animated: false )
@@ -307,9 +307,9 @@ public class M13Checkbox: UIControl {
307
307
}
308
308
309
309
if animated {
310
- manager . animate ( checkState, toState: newState)
310
+ controller . animate ( checkState, toState: newState)
311
311
} else {
312
- manager . resetLayersForState ( newState)
312
+ controller . resetLayersForState ( newState)
313
313
}
314
314
}
315
315
@@ -339,10 +339,10 @@ public class M13Checkbox: UIControl {
339
339
/// The duration of the animation that occurs when the checkbox switches states. The default is 0.3 seconds.
340
340
@IBInspectable public var animationDuration : TimeInterval {
341
341
get {
342
- return manager . animationGenerator. animationDuration
342
+ return controller . animationGenerator. animationDuration
343
343
}
344
344
set {
345
- manager . animationGenerator. animationDuration = newValue
345
+ controller . animationGenerator. animationDuration = newValue
346
346
}
347
347
}
348
348
@@ -365,14 +365,10 @@ public class M13Checkbox: UIControl {
365
365
newManager. secondaryTintColor = secondaryTintColor
366
366
newManager. secondaryCheckmarkTintColor = secondaryCheckmarkTintColor
367
367
newManager. hideBox = hideBox
368
-
369
- newManager. paths. boxLineWidth = manager. paths. boxLineWidth
370
- newManager. paths. boxType = manager. paths. boxType
371
- newManager. paths. checkmarkLineWidth = manager. paths. checkmarkLineWidth
372
- newManager. paths. cornerRadius = manager. paths. cornerRadius
373
- newManager. paths. markType = manager. paths. markType
374
-
375
- newManager. animationGenerator. animationDuration = manager. animationGenerator. animationDuration
368
+ newManager. pathGenerator = controller. pathGenerator
369
+ newManager. animationGenerator. animationDuration = controller. animationGenerator. animationDuration
370
+ newManager. state = controller. state
371
+ newManager. setMarkType ( type: controller. markType, animated: false )
376
372
377
373
// Set up the inital state.
378
374
for aLayer in newManager. layersToDisplay {
@@ -381,13 +377,8 @@ public class M13Checkbox: UIControl {
381
377
382
378
// Layout and reset
383
379
newManager. resetLayersForState ( checkState)
384
- manager = newManager
385
-
386
- // TODO: - Add support for missing animations.
387
- if markType == . radio && stateChangeAnimation == . spiral {
388
- stateChangeAnimation = . stroke
389
- print ( " WARNING: The spiral animation is currently unsupported with a radio mark. " )
390
- }
380
+ controller = newManager
381
+
391
382
}
392
383
}
393
384
@@ -414,99 +405,96 @@ public class M13Checkbox: UIControl {
414
405
/// The color of the checkbox's tint color when not in the unselected state. The tint color is is the main color used when not in the unselected state.
415
406
@IBInspectable public var secondaryTintColor : UIColor ? {
416
407
get {
417
- return manager . secondaryTintColor
408
+ return controller . secondaryTintColor
418
409
}
419
410
set {
420
- manager . secondaryTintColor = newValue
411
+ controller . secondaryTintColor = newValue
421
412
}
422
413
}
423
414
424
415
/// The color of the checkmark when it is displayed against a filled background.
425
416
@IBInspectable public var secondaryCheckmarkTintColor : UIColor ? {
426
417
get {
427
- return manager . secondaryCheckmarkTintColor
418
+ return controller . secondaryCheckmarkTintColor
428
419
}
429
420
set {
430
- manager . secondaryCheckmarkTintColor = newValue
421
+ controller . secondaryCheckmarkTintColor = newValue
431
422
}
432
423
}
433
424
434
425
/// The stroke width of the checkmark.
435
426
@IBInspectable public var checkmarkLineWidth : CGFloat {
436
427
get {
437
- return manager . paths . checkmarkLineWidth
428
+ return controller . pathGenerator . checkmarkLineWidth
438
429
}
439
430
set {
440
- manager . paths . checkmarkLineWidth = newValue
441
- manager . resetLayersForState ( checkState)
431
+ controller . pathGenerator . checkmarkLineWidth = newValue
432
+ controller . resetLayersForState ( checkState)
442
433
}
443
434
}
444
435
445
- // The type of mark to display.
436
+ /// The type of mark to display.
446
437
@IBInspectable public var markType : MarkType {
447
438
get {
448
- return manager . paths . markType
439
+ return controller . markType
449
440
}
450
441
set {
451
- manager. paths. markType = newValue
452
-
453
- // TODO: - Add support for missing animations.
454
- if markType == . radio && stateChangeAnimation == . spiral {
455
- manager. paths. markType = . checkmark
456
- print ( " WARNING: The spiral animation is currently unsupported with a radio mark. " )
457
- }
458
-
459
- manager. resetLayersForState ( checkState)
442
+ controller. markType = newValue
460
443
setNeedsLayout ( )
461
444
}
462
445
}
463
446
447
+ /// Set the mark type with the option of animating the change.
448
+ public func setMarkType( markType: MarkType , animated: Bool ) {
449
+ controller. setMarkType ( type: markType, animated: animated)
450
+ }
451
+
464
452
/// The stroke width of the box.
465
453
@IBInspectable public var boxLineWidth : CGFloat {
466
454
get {
467
- return manager . paths . boxLineWidth
455
+ return controller . pathGenerator . boxLineWidth
468
456
}
469
457
set {
470
- manager . paths . boxLineWidth = newValue
471
- manager . resetLayersForState ( checkState)
458
+ controller . pathGenerator . boxLineWidth = newValue
459
+ controller . resetLayersForState ( checkState)
472
460
}
473
461
}
474
462
475
463
/// The corner radius of the box if the box type is square.
476
464
@IBInspectable public var cornerRadius : CGFloat {
477
465
get {
478
- return manager . paths . cornerRadius
466
+ return controller . pathGenerator . cornerRadius
479
467
}
480
468
set {
481
- manager . paths . cornerRadius = newValue
469
+ controller . pathGenerator . cornerRadius = newValue
482
470
setNeedsLayout ( )
483
471
}
484
472
}
485
473
486
474
/// The shape of the checkbox.
487
475
public var boxType : BoxType {
488
476
get {
489
- return manager . paths . boxType
477
+ return controller . pathGenerator . boxType
490
478
}
491
479
set {
492
- manager . paths . boxType = newValue
480
+ controller . pathGenerator . boxType = newValue
493
481
setNeedsLayout ( )
494
482
}
495
483
}
496
484
497
485
/// Wether or not to hide the checkbox.
498
486
@IBInspectable public var hideBox : Bool {
499
487
get {
500
- return manager . hideBox
488
+ return controller . hideBox
501
489
}
502
490
set {
503
- manager . hideBox = newValue
491
+ controller . hideBox = newValue
504
492
}
505
493
}
506
494
507
495
public override func tintColorDidChange( ) {
508
496
super. tintColorDidChange ( )
509
- manager . tintColor = tintColor
497
+ controller . tintColor = tintColor
510
498
}
511
499
512
500
//----------------------------
@@ -516,8 +504,8 @@ public class M13Checkbox: UIControl {
516
504
public override func layoutSubviews( ) {
517
505
super. layoutSubviews ( )
518
506
// Update size
519
- manager . paths . size = min ( frame. size. width, frame. size. height)
507
+ controller . pathGenerator . size = min ( frame. size. width, frame. size. height)
520
508
// Layout
521
- manager . layoutLayers ( )
509
+ controller . layoutLayers ( )
522
510
}
523
511
}
0 commit comments