绘制六边形的方法

floatviewWidth =45;

UIBezierPath* path = [UIBezierPathbezierPath];

path.lineWidth=2;

[[UIColorwhiteColor]setStroke];

[pathmoveToPoint:CGPointMake((sin(M_1_PI/180*60)) * (viewWidth /2), (viewWidth /4))];

[pathaddLineToPoint:CGPointMake((viewWidth /2),0)];

[pathaddLineToPoint:CGPointMake(viewWidth - ((sin(M_1_PI/180*60)) * (viewWidth /2)), (viewWidth /4))];

[pathaddLineToPoint:CGPointMake(viewWidth - ((sin(M_1_PI/180*60)) * (viewWidth /2)), (viewWidth /2) + (viewWidth /4))];

[pathaddLineToPoint:CGPointMake((viewWidth /2), viewWidth)];

[pathaddLineToPoint:CGPointMake((sin(M_1_PI/180*60)) * (viewWidth /2), (viewWidth /2) + (viewWidth /4))];

[pathclosePath];

CAShapeLayer* shapLayer = [CAShapeLayerlayer];

shapLayer.lineWidth=2;

shapLayer.strokeColor= [UIColorwhiteColor].CGColor;

shapLayer.path= path.CGPath;

self.coverImageView.layer.mask= shapLayer;

你可能感兴趣的:(绘制六边形的方法)