iOS开发 画六边形(多边形)

- (void)drawRect:(CGRect)rect {

  UIBezierPath * path = [UIBezierPath bezierPath];

  [path moveToPoint:CGPointMake(fView_Width(self)/2., 6*DX_Proportion)];

  [path addLineToPoint:CGPointMake(fView_Width(self) - 6*DX_Proportion, 30/2.*DX_Proportion + 6*DX_Proportion)];

  [path addLineToPoint:CGPointMake(fView_Width(self) - 6*DX_Proportion, 90/2.*DX_Proportion + 6*DX_Proportion)];

  [path addLineToPoint:CGPointMake(fView_Width(self)/2., fView_Height(self) - 6*DX_Proportion)];

  [path addLineToPoint:CGPointMake(6*DX_Proportion, 90/2.*DX_Proportion + 6*DX_Proportion)];

  [path addLineToPoint:CGPointMake(6*DX_Proportion, 30/2.*DX_Proportion + 6*DX_Proportion)];

  [path closePath];

  path.lineWidth = 3*DX_Proportion;

  [self.linColor set];

  [path stroke];    

  

  CAShapeLayer * shapLayer = [CAShapeLayer layer];

  

  shapLayer.path = path.CGPath;

  self.imageView.layer.mask = shapLayer;

}

原文地址:https://www.cnblogs.com/diweinan/p/6214081.html