-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.transform = CGAffineTransformMakeRotation(M_PI / 6);
}
return self;
}
-(void)drawRect:(CGRect)rect{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ctx, [UIColor clearColor].CGColor);
CGContextSetFillColorWithColor(ctx, [UIColor orangeColor].CGColor);
CGContextSetLineWidth(ctx, 1.5);
CGRect theRect = rect;
CGPoint _centerPoint = CGPointMake(theRect.size.width / 2 + theRect.origin.x, theRect.size.height / 2 + theRect.origin.y);
CGFloat _r = MIN(theRect.size.width / 2, theRect.size.height / 2);
CGFloat radPerV = M_PI * 2 / 6;
for (NSInteger i = 0; i <= 6; i++)
{
if (i == 0) {
CGContextMoveToPoint(ctx, _centerPoint.x, _centerPoint.y - _r);
}else{
CGContextAddLineToPoint(ctx, _centerPoint.x - _r * sin(i * radPerV), _centerPoint.y - _r * cos(i * radPerV));
}
}
CGContextDrawPath(ctx, kCGPathFillStroke);
}
转载于:https://my.oschina.net/iOStianlele/blog/630898