JKDotView.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // JKDotView.m
  3. // Lock
  4. //
  5. // Created by Jack on 2016/10/13.
  6. // Copyright © 2016年 mini1. All rights reserved.
  7. //
  8. #import "JKDotView.h"
  9. @interface JKDotView ()
  10. @property (nonatomic,strong) CAShapeLayer *inscribedCircleLayer;///<内切圆
  11. @end
  12. @implementation JKDotView
  13. -(CAShapeLayer *)inscribedCircleLayer{
  14. if (!_inscribedCircleLayer) {
  15. _inscribedCircleLayer = [CAShapeLayer layer];
  16. _inscribedCircleLayer.strokeColor = self.strokColor.CGColor;
  17. _inscribedCircleLayer.fillColor = [UIColor clearColor].CGColor;
  18. _inscribedCircleLayer.lineWidth = 1.0f;
  19. }
  20. return _inscribedCircleLayer;
  21. }
  22. - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
  23. self.inscribedCircleLayer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
  24. [self.layer addSublayer:self.inscribedCircleLayer];
  25. }
  26. - (instancetype)initWithFrame:(CGRect)frame {
  27. if (self = [super initWithFrame:frame]) {
  28. self.backgroundColor = [UIColor clearColor];
  29. [self.layer setNeedsDisplay];
  30. }
  31. return self;
  32. }
  33. - (instancetype)initWithFrame:(CGRect)frame strokColor:(UIColor *)strokColor fillColor:(UIColor *)fillColor {
  34. if (self = [super initWithFrame:frame]) {
  35. self.strokColor = strokColor;
  36. self.fillColor = fillColor;
  37. self.backgroundColor = [UIColor clearColor];
  38. [self.layer setNeedsDisplay];
  39. }
  40. return self;
  41. }
  42. - (void)setState:(JKDotState)state {
  43. _state = state;
  44. switch (state) {
  45. case JKDotStateNormal:{
  46. _inscribedCircleLayer.strokeColor = self.strokColor.CGColor;
  47. _inscribedCircleLayer.fillColor = [UIColor clearColor].CGColor;
  48. }
  49. break;
  50. case JKDotStateSelected:{
  51. _inscribedCircleLayer.strokeColor = self.fillColor.CGColor;
  52. _inscribedCircleLayer.fillColor = self.fillColor.CGColor;
  53. }
  54. break;
  55. default:
  56. break;
  57. }
  58. }
  59. - (UIColor *)strokColor {
  60. return _strokColor ? _strokColor : [UIColor blackColor];
  61. }
  62. - (UIColor *)fillColor {
  63. return _fillColor ? _fillColor : [UIColor blackColor];
  64. }
  65. @end