开发者

Draw line with special shape like dotted(China Point)

开发者 https://www.devze.com 2023-02-04 07:08 出处:网络
IS it possible to draw line with special shape for example like dotted(China Point) ? i draw line with below code

IS it possible to draw line with special shape for example like dotted(China Point) ? i draw line with below code

UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 480)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.867, 0.867, 0.867, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextM开发者_开发问答oveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


Maybe CGContextSetLineDash is what you want. It sets the pattern for dashed lines in a graphics context.

void CGContextSetLineDash (
   CGContextRef c,
   CGFloat phase,
   const CGFloat lengths[],
   size_t count
);

This example draws a line with circles (diameter: 20 points, distance: 40 points):

CGContextSetLineWidth(context, 20.0);
CGFloat dash[] = {0.0, 40.0};
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineDash(context, 0.0, dash, 2);
CGContextMoveToPoint(context, 10.0, 30.0);
CGContextAddLineToPoint(context, 310.0, 30.0);
CGContextStrokePath(context);
0

精彩评论

暂无评论...
验证码 换一张
取 消