绘制六边形的方法

2015-10-28  本文已影响92人  lion_xion

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;

上一篇下一篇

猜你喜欢

热点阅读