// // JKDotView.m // Lock // // Created by Jack on 2016/10/13. // Copyright © 2016年 mini1. All rights reserved. // #import "JKDotView.h" @interface JKDotView () @property (nonatomic,strong) CAShapeLayer *inscribedCircleLayer;///<内切圆 @end @implementation JKDotView -(CAShapeLayer *)inscribedCircleLayer{ if (!_inscribedCircleLayer) { _inscribedCircleLayer = [CAShapeLayer layer]; _inscribedCircleLayer.strokeColor = self.strokColor.CGColor; _inscribedCircleLayer.fillColor = [UIColor clearColor].CGColor; _inscribedCircleLayer.lineWidth = 1.0f; } return _inscribedCircleLayer; } - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { self.inscribedCircleLayer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath; [self.layer addSublayer:self.inscribedCircleLayer]; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; [self.layer setNeedsDisplay]; } return self; } - (instancetype)initWithFrame:(CGRect)frame strokColor:(UIColor *)strokColor fillColor:(UIColor *)fillColor { if (self = [super initWithFrame:frame]) { self.strokColor = strokColor; self.fillColor = fillColor; self.backgroundColor = [UIColor clearColor]; [self.layer setNeedsDisplay]; } return self; } - (void)setState:(JKDotState)state { _state = state; switch (state) { case JKDotStateNormal:{ _inscribedCircleLayer.strokeColor = self.strokColor.CGColor; _inscribedCircleLayer.fillColor = [UIColor clearColor].CGColor; } break; case JKDotStateSelected:{ _inscribedCircleLayer.strokeColor = self.fillColor.CGColor; _inscribedCircleLayer.fillColor = self.fillColor.CGColor; } break; default: break; } } - (UIColor *)strokColor { return _strokColor ? _strokColor : [UIColor blackColor]; } - (UIColor *)fillColor { return _fillColor ? _fillColor : [UIColor blackColor]; } @end